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

support more metadata types #28

Closed
wants to merge 1 commit into from
Closed

support more metadata types #28

wants to merge 1 commit into from

Conversation

ruslandoga
Copy link
Contributor

@ruslandoga ruslandoga commented Dec 22, 2023

This PR adds support for more metadata types.

Closes #25

"level" => "debug",
"line" => line,
"mfa" => "ExJsonLoggerTest.\"test format/4 structured\"/1",
"msg" => "[msg: \"this is a message\", where: \"somewhere\", ok: :ok]",
Copy link
Contributor Author

@ruslandoga ruslandoga Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be JSON, but it'd probably require a custom :logger formatter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a demo of what it could be like: https://github.com/ruslandoga/logger_json_formatter

Copy link
Contributor Author

@ruslandoga ruslandoga Dec 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should format/2 be added to this project to support the new formatters or should it be left for another project?

@@ -1,5 +1,5 @@
defmodule ExJsonLogger.Plug.LoggerTest do
use ExUnit.Case, async: true
Copy link
Contributor Author

@ruslandoga ruslandoga Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting interleaved messages in capture_log. Plus most tests mutate global state (logger config) which doesn't work well with async tests.

@ruslandoga ruslandoga marked this pull request as ready for review December 24, 2023 09:37
defp format_metadata({key, atom}) when is_atom(atom) do
value =
case Atom.to_string(atom) do
"Elixir." <> rest -> rest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be in favor of leaving these untouched, even if they do contain an Elixir. prefix. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep the behavior the same as in the default formatter :)

{"time", format_timestamp(timestamp)},
{"msg", IO.iodata_to_binary(msg)}
| metadata(metadata)
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change from map to list done for performance reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mostly done for simplicity. This way, metadata/1 does both processing and filtering without the need for extra Map.merge/2 and Map.delete/2 operations.

@ruslandoga ruslandoga closed this by deleting the head repository Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support more metadata types
2 participants