From 70c4a8bf93bad8a137e30506262e78a11458dd32 Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:26:14 -0300 Subject: [PATCH 1/3] feat: handles/reports Logger.error --- lib/tower/logger_handler.ex | 4 ++++ test/tower_test.exs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/tower/logger_handler.ex b/lib/tower/logger_handler.ex index 4382786..d9ff076 100644 --- a/lib/tower/logger_handler.ex +++ b/lib/tower/logger_handler.ex @@ -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)}" diff --git a/test/tower_test.exs b/test/tower_test.exs index 8b29d13..0dd62f4 100644 --- a/test/tower_test.exs +++ b/test/tower_test.exs @@ -158,6 +158,29 @@ defmodule TowerTest do assert is_list(stacktrace) end + @tag capture_log: true + test "reports a Logger.error" do + Tower.EphemeralReporter.start_link([]) + + in_unlinked_process(fn -> + require Logger + Logger.error("Something went wrong here") + end) + + assert( + [ + %{ + time: _, + type: _, + reason: "Something went wrong here", + stacktrace: stacktrace + } + ] = Tower.EphemeralReporter.errors() + ) + + assert is_list(stacktrace) + end + defp in_unlinked_process(fun) when is_function(fun, 0) do {:ok, pid} = Task.Supervisor.start_link() From efe289c310be06d9920224044fb6680795937fd3 Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:49:16 -0300 Subject: [PATCH 2/3] assert type --- test/tower_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tower_test.exs b/test/tower_test.exs index 379e014..4aa5261 100644 --- a/test/tower_test.exs +++ b/test/tower_test.exs @@ -154,7 +154,7 @@ defmodule TowerTest do [ %{ time: _, - type: _, + type: :error, reason: "Something went wrong here", stacktrace: stacktrace } From 90325364e74382e2c0889400d8310f73f569279f Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Fri, 7 Jun 2024 10:05:12 -0300 Subject: [PATCH 3/3] stacktrace assert --- test/tower_test.exs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/tower_test.exs b/test/tower_test.exs index 4aa5261..6b85fec 100644 --- a/test/tower_test.exs +++ b/test/tower_test.exs @@ -156,12 +156,10 @@ defmodule TowerTest do time: _, type: :error, reason: "Something went wrong here", - stacktrace: stacktrace + stacktrace: [] } ] = reported_errors() ) - - assert is_list(stacktrace) end defp in_unlinked_process(fun) when is_function(fun, 0) do