-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,65 @@ | ||
defmodule Tower.Event do | ||
defstruct [:time, :level, :kind, :reason, :stacktrace, :log_event_meta] | ||
defstruct [:time, :level, :kind, :reason, :stacktrace, :metadata] | ||
|
||
@type metadata :: %{log_event: :logger.log_event()} | ||
|
||
@type t :: %__MODULE__{ | ||
time: :logger.timestamp(), | ||
level: :logger.level(), | ||
kind: :error | :exit | :throw | :message, | ||
reason: Exception.t() | term(), | ||
stacktrace: Exception.stacktrace(), | ||
log_event_meta: :logger.metadata() | ||
metadata: metadata() | ||
} | ||
|
||
def from_exception(exception, stacktrace, log_event_meta) do | ||
def from_exception(exception, stacktrace, log_event) do | ||
%__MODULE__{ | ||
time: Map.get(log_event_meta, :time, :logger.timestamp()), | ||
time: log_event[:meta][:time] || :logger.timestamp(), | ||
level: :error, | ||
kind: :error, | ||
reason: exception, | ||
stacktrace: stacktrace, | ||
log_event_meta: log_event_meta | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
def from_exit(reason, stacktrace, log_event_meta) do | ||
def from_exit(reason, stacktrace, log_event) do | ||
%__MODULE__{ | ||
time: Map.get(log_event_meta, :time, :logger.timestamp()), | ||
time: log_event[:meta][:time] || :logger.timestamp(), | ||
level: :error, | ||
kind: :exit, | ||
reason: reason, | ||
stacktrace: stacktrace, | ||
log_event_meta: log_event_meta | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
def from_throw(reason, stacktrace, log_event_meta) do | ||
def from_throw(reason, stacktrace, log_event) do | ||
%__MODULE__{ | ||
time: Map.get(log_event_meta, :time, :logger.timestamp()), | ||
time: log_event[:meta][:time] || :logger.timestamp(), | ||
level: :error, | ||
kind: :throw, | ||
reason: reason, | ||
stacktrace: stacktrace, | ||
log_event_meta: log_event_meta | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
def from_message(level, message, log_event_meta) do | ||
def from_message(level, message, log_event) do | ||
%__MODULE__{ | ||
time: Map.get(log_event_meta, :time, :logger.timestamp()), | ||
time: log_event[:meta][:time] || :logger.timestamp(), | ||
level: level, | ||
kind: :message, | ||
reason: message, | ||
log_event_meta: log_event_meta | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters