Skip to content

Commit

Permalink
Include file, line and mfa in basic formatter metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ppeerttu committed Oct 14, 2024
1 parent 584a624 commit 9a2decf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/logger_json/formatter/metadata.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LoggerJSON.Formatter.Metadata do
@moduledoc false

@ignored_metadata_keys ~w[ansi_color initial_call crash_reason pid gl mfa report_cb time]a
@ignored_metadata_keys ~w[ansi_color initial_call crash_reason pid gl report_cb time]a

@doc """
Takes current metadata option value and updates it to exclude the given keys.
Expand Down
3 changes: 1 addition & 2 deletions lib/logger_json/formatters/basic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ defmodule LoggerJSON.Formatters.Basic do

@behaviour LoggerJSON.Formatter

@processed_metadata_keys ~w[file line mfa
otel_span_id span_id
@processed_metadata_keys ~w[otel_span_id span_id
otel_trace_id trace_id
conn]a

Expand Down
1 change: 0 additions & 1 deletion test/logger_json/formatter/metadata_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ defmodule LoggerJSON.Formatter.MetadataTest do
crash_reason: "crash_reason",
pid: "pid",
gl: "gl",
mfa: "mfa",
report_cb: "report_cb",
time: "time"
}
Expand Down
18 changes: 18 additions & 0 deletions test/logger_json/formatters/basic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ defmodule LoggerJSON.Formatters.BasicTest do
assert log["trace"] == "294740ce41cc9f202dedb563db123532"
end

test "logs file, line and mfa as metadata" do
metadata =
capture_log(fn ->
Logger.debug("Hello")
end)
|> decode_or_print_error()
|> Map.get("metadata")

assert metadata |> Map.get("file") |> to_string() =~ "logger_json/formatters/basic_test.exs"
assert metadata |> Map.get("line") |> is_integer()

assert metadata["mfa"] === [
"Elixir.LoggerJSON.Formatters.BasicTest",
"test logs file, line and mfa as metadata",
1
]
end

test "logs metadata" do
Logger.metadata(
date: Date.utc_today(),
Expand Down

0 comments on commit 9a2decf

Please sign in to comment.