Skip to content

Commit

Permalink
feat: handles/reports Logger.error (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy authored Jun 7, 2024
1 parent b09911a commit c319188
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/tower/logger_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ defmodule Tower.LoggerHandler do
end
end

def log(%{level: :error, msg: {:string, reason}, meta: meta}, _config) do
Tower.report(:error, reason, [], meta)
end

def log(log_event, _config) do
IO.puts(
"[Tower.LoggerHandler] UNHANDLED LOG EVENT log_event=#{inspect(log_event, pretty: true)}"
Expand Down
19 changes: 19 additions & 0 deletions test/tower_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ defmodule TowerTest do
assert is_list(stacktrace)
end

@tag capture_log: true
test "reports a Logger.error" do
in_unlinked_process(fn ->
require Logger
Logger.error("Something went wrong here")
end)

assert(
[
%{
time: _,
type: :error,
reason: "Something went wrong here",
stacktrace: []
}
] = reported_errors()
)
end

defp in_unlinked_process(fun) when is_function(fun, 0) do
{:ok, pid} = Task.Supervisor.start_link()

Expand Down

0 comments on commit c319188

Please sign in to comment.