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

Use :logger_handler formatter for JSON #4855

Closed
wants to merge 13 commits into from
Closed

Conversation

ruslandoga
Copy link
Contributor

@ruslandoga ruslandoga commented Nov 26, 2024

This PR switches from Logger backends to :logger handlers.

Card: https://3.basecamp.com/5308029/buckets/29267832/card_tables/cards/7610404292

Plan:

  • remove :console backend
  • WIP add "native" JSON formatter
  • Sentry.LoggerBackend -> Sentry.LoggerHandler
  • ensure overload protection

Should JSON formatter be a library?

Other people might find it useful. I didn't find anything like it at the time of my original implementation (it was all about formatters for backends or backends back then). But maybe there is something out there now. I'll need to check.


UPDATE: Probably not, since a very popular LoggerJSON supports handlers as of 7 months ago.

Would it make sense to switch to it? Right now its "Basic" format is a bit different from what ex_json_logger was using. But seems like it might allow configuration.

Logger.info("hello")
Logger.info("hello", request_id: 1)

LoggerJSON:

{"message":"hello","time":"2024-11-26T08:45:10.982Z","metadata":{},"severity":"info"}
{"message":"hello","time":"2024-11-26T08:45:10.982Z","metadata":{"request_id":1},"severity":"info"}

ExJsonLogger @ 1.4.0 (currently used):

{"time":"2024-11-26 15:48:43.186","msg":"hello","level":"info"}
{"time":"2024-11-26 16:03:19.836","msg":"hello","level":"info","request_id":1}

This PR:

{"level":"info","time":"2024-11-26 15:47:13.136","msg":"hello"}
{"level":"info","time":"2024-11-27 11:54:52.559","msg":"hello","request_id":1}

Differences between LoggerJSON and ExJsonLogger:

  • UTC vs system time (can be configured with utc_log Logger option in ExJsonLogger and this PR)
  • different key names
  • meta is nested instead of merged
  • rescues exceptions during formatting (not sure if necessary)

Differences between this PR and LoggerJSON:

  • more similar to the default Logger.Formatter (same configuration, same logic in most cases)
  • is a bit faster since it performs less work / doesn't require configurability

Tests

  • Automated tests have been added
  • This PR does not require tests

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@ruslandoga
Copy link
Contributor Author

ruslandoga commented Nov 28, 2024

Closing in favor of #4862 to keep changes minimal.

@ruslandoga ruslandoga closed this Nov 28, 2024
@ruslandoga ruslandoga deleted the logger-handlers branch November 28, 2024 07:31
@ruslandoga ruslandoga mentioned this pull request Nov 28, 2024
4 tasks
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.

1 participant