Skip to content

Emit log events as :warning instead of :warn#1

Merged
jvf merged 1 commit intomasterfrom
fix-emitted-level
Feb 7, 2024
Merged

Emit log events as :warning instead of :warn#1
jvf merged 1 commit intomasterfrom
fix-emitted-level

Conversation

@jvf
Copy link

@jvf jvf commented Feb 7, 2024

In Elixir v1.15 a deprecation warning is emitted if the deprecated log level shortcut warn is:

warning: the log level :warn is deprecated, use :warning instead
  (logger 1.15.7) lib/logger.ex:1137: Logger.elixir_level_to_erlang_level/1
  (logger 1.15.7) lib/logger.ex:591: Logger.compare_levels/2
  (syslog 1.0.0) lib/syslog.ex:37: Logger.Backends.Syslog.handle_event/2
  (stdlib 5.2) gen_event.erl:814: :gen_event.server_update/4
  (stdlib 5.2) gen_event.erl:796: :gen_event.server_notify/4
  (stdlib 5.2) gen_event.erl:538: :gen_event.handle_msg/6

At the same time the Logger passes the log level as warn to the old-style logger backends. Presumably for backwards compatibility. It thus falls to the logger backend to use the correct level identifier when emitting events.

The syslog backend is such a logger backend. This PR adds a code snippet to transform the received level warn to warning.

cc: @harunzengin @weisslj

@jvf jvf requested a review from harunzengin February 7, 2024 12:24
@jvf jvf self-assigned this Feb 7, 2024
Convert :warn to :warning to avoid getting a deprecation warning from
Logger every time a :warning is emitted. The deprecation warning was
added in Elixir v1.15.
@jvf jvf force-pushed the fix-emitted-level branch from ea61e4b to cc8f647 Compare February 7, 2024 12:30
@jvf
Copy link
Author

jvf commented Feb 7, 2024

I also created an identical PR to the upstream repo, see smpallen99#23.

@jvf jvf merged commit 0a20829 into master Feb 7, 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.

1 participant

Comments