Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handles/reports Logger.error #11

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -18,7 +18,7 @@
@tag capture_log: true
test "reports arithmetic error" do
in_unlinked_process(fn ->
1 / 0

Check warning on line 21 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.12)

the call to //2 will fail with ArithmeticError

Check warning on line 21 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.14, 24.3.4.17)

the call to //2 will fail with ArithmeticError

Check warning on line 21 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.13, 23.3.4.20)

this expression will fail with ArithmeticError

Check warning on line 21 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.12)

the call to //2 will fail with ArithmeticError

Check warning on line 21 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.14, 24.3.4.17)

the call to //2 will fail with ArithmeticError

Check warning on line 21 in test/tower_test.exs

View workflow job for this annotation

GitHub Actions / main (1.13, 23.3.4.20)

this expression will fail with ArithmeticError
end)

assert(
Expand Down Expand Up @@ -143,6 +143,25 @@
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