-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into unrecognized
- Loading branch information
Showing
11 changed files
with
377 additions
and
86 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 |
---|---|---|
|
@@ -24,3 +24,5 @@ tower-*.tar | |
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
/priv/plts |
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
defmodule Tower.Event do | ||
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(), | ||
metadata: metadata() | ||
} | ||
|
||
def from_exception(exception, stacktrace, options \\ []) do | ||
log_event = Keyword.get(options, :log_event) | ||
|
||
%__MODULE__{ | ||
time: log_event[:meta][:time] || now(), | ||
level: :error, | ||
kind: :error, | ||
reason: exception, | ||
stacktrace: stacktrace, | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
def from_exit(reason, stacktrace, options \\ []) do | ||
log_event = Keyword.get(options, :log_event) | ||
|
||
%__MODULE__{ | ||
time: log_event[:meta][:time] || now(), | ||
level: :error, | ||
kind: :exit, | ||
reason: reason, | ||
stacktrace: stacktrace, | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
def from_throw(reason, stacktrace, options \\ []) do | ||
log_event = Keyword.get(options, :log_event) | ||
|
||
%__MODULE__{ | ||
time: log_event[:meta][:time] || now(), | ||
level: :error, | ||
kind: :throw, | ||
reason: reason, | ||
stacktrace: stacktrace, | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
def from_message(level, message, options \\ []) do | ||
log_event = Keyword.get(options, :log_event) | ||
|
||
%__MODULE__{ | ||
time: log_event[:meta][:time] || now(), | ||
level: level, | ||
kind: :message, | ||
reason: message, | ||
metadata: %{ | ||
log_event: log_event | ||
} | ||
} | ||
end | ||
|
||
defp now do | ||
:logger.timestamp() | ||
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
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,14 +1,6 @@ | ||
defmodule Tower.Reporter do | ||
@doc """ | ||
Reports an exception. | ||
Reports events. | ||
""" | ||
@callback report_exception(exception :: Exception.t(), stacktrace :: list()) :: :ok | ||
@callback report_exception(exception :: Exception.t(), stacktrace :: list(), metadata :: map()) :: | ||
:ok | ||
@callback report_throw(reason :: term(), stacktrace :: list()) :: :ok | ||
@callback report_throw(reason :: term(), stacktrace :: list(), metadata :: map()) :: :ok | ||
@callback report_exit(reason :: term(), stacktrace :: list()) :: :ok | ||
@callback report_exit(reason :: term(), stacktrace :: list(), metadata :: map()) :: :ok | ||
@callback report_message(level :: atom(), message :: term()) :: :ok | ||
@callback report_message(level :: atom(), message :: term(), metadata :: map()) :: :ok | ||
@callback report_event(event :: Tower.Event.t()) :: :ok | ||
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
Oops, something went wrong.