Skip to content

Commit

Permalink
Always return :ok even if nothing is logged (#126)
Browse files Browse the repository at this point in the history
* Always return :ok even if nothing is logged

* add a test
  • Loading branch information
adamu authored Aug 6, 2024
1 parent cad5979 commit 2e72e28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/logger_json/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ if Code.ensure_loaded?(Plug) and Code.ensure_loaded?(:telemetry) do
conn: conn,
duration_μs: duration
)
else
:ok
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/logger_json/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -593,5 +593,16 @@ defmodule LoggerJSON.PlugTest do
end
end

test "telemetry_logging_handler/4 returns :ok even when Logger is not called" do
log =
capture_log(fn ->
assert :ok == telemetry_logging_handler([], %{duration: 0}, %{conn: %Plug.Conn{}}, false)

Logger.flush()
end)

assert log == ""
end

def ignore_log(%Plug.Conn{}, :arg), do: false
end

0 comments on commit 2e72e28

Please sign in to comment.