-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Emit notice logs in :console backend #11304
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
Conversation
Yes, unfortunately we cannot introduce this as it would break all existing Logger backends, as they will now receive a format they don't know how to handle. However, what we can do instead is to change the |
@josevalim an Is a little overhead (keyword find) in re-translating back elixir level into erlang level acceptable in |
yes.. this is not very "backward compatible".. I guess adding some config flag to enable it, and default it to false.. would be proper (?)
e654458
to
cc55a82
Compare
I've added support for Is this what you meant? It's in any case breaking the format of preexisting log collections in case someone was logging to notice. |
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: Alberto Sartori <alberto.sartori.as@gmail.com>
we should also convert back erlang |
In addition, the same logic should be used also in the In this way, it goes also through the |
unintended at all. |
level = case level do | ||
:warning -> :warn | ||
_ -> level | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, let's not convert back. Logger.warn
is already deprecated, so it is a good opportunity to move to warning
. :)
@riccardomanfrin also please take a look at CI. We need to add at least two tests:
|
What about pad levels?
@riccardomanfrin there is a failure in ex_unit suite now because of the changes: |
/cc @hauleth in case you want to review it too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring all the comments, I have different concept how we can add support for more features from Erlang logger instead.
- add new optional callback for the backends, for example
type/0
that will return:legacy | :rich
and will default to:legacy
if not defined - for
:legacy
backends receives message in the current, tuple based, format - for
:rich
(can use different name there) backend receives message in "raw" format from the Erlang (possibly with some alterations to wrap:report_cb
for example)
This approach should give us a way to make full transition in future (possibly still in multiple steps).
What do you think @josevalim about such approach? It would give a way to have smother transition period, and possibly migrate to "new" format even without bumping Logger's major version (which would imply bumping Elixir's major version).
@@ -138,6 +138,8 @@ defmodule Logger.Backends.Console do | |||
def handle_event({level, _gl, {Logger, msg, ts, md}}, state) do | |||
%{level: log_level, ref: ref, buffer_size: buffer_size, max_buffer: max_buffer} = state | |||
|
|||
{:erl_level, level} = List.keyfind(md, :erl_level, 0, {:erl_level, level}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
md
is defined to be keyword list, so why use List.keyfind/4
instead of Keyword.get/3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are fine. List.keyfind can be a tiny bit more efficient.
@@ -163,10 +163,10 @@ defmodule Logger.Formatter do | |||
defp output(:levelpad, level, _, _, _), do: levelpad(level) | |||
defp output(other, _, _, _, _), do: other | |||
|
|||
defp levelpad(:debug), do: "" | |||
# TODO: Deprecate me on Elixir v1.13+ or later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
levelpad is not very useful now when one of the levels is "critical". There will be just too much padding on something like "info" (4 chars to be more precise).
alert: Keyword.get(colors, :debug, :red), | ||
critical: Keyword.get(colors, :debug, :red), | ||
emergency: Keyword.get(colors, :debug, :red), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be:
alert: Keyword.get(colors, :debug, :red), | |
critical: Keyword.get(colors, :debug, :red), | |
emergency: Keyword.get(colors, :debug, :red), | |
alert: Keyword.get(colors, :alert, :red), | |
critical: Keyword.get(colors, :critical, :red), | |
emergency: Keyword.get(colors, :emergency, :red), |
However in my logger_colorful
I have used background color for all these levels to mark that it is "higher than error".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Those should be all error. We should add a fallback for custom colors in another PR.
error: Keyword.get(colors, :error, :red), | ||
notice: Keyword.get(colors, :info, :normal), | ||
enabled: Keyword.get(colors, :enabled, IO.ANSI.enabled?()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order of the keys in this map is now weird. Earlier it was in decreasing verbosity, and now it is "whatever".
@hauleth thanks for the review. What you described is precisely the plan for #7328. The idea is that the old handlers will be wrapped by an internal gen_event handler and the new handle_event message will be much closer to what Erlang emits. I would say this PR is something necessary to help us get there, so the backend is already ready for the new version. |
💚 💙 💜 💛 ❤️ |
@josevalim you probably meant #7928. I can see if I can craft something like that as a part of Hacktoberfest. I wouldn't say that it is strictly needed to get us there, but for sure can ease transition period (unless I really will be able to craft my PR before 1.13). |
Yes, correct on both. :) |
yes.. this is not very "backward compatible"..
I guess adding some config flag to enable it, and
default it to false.. would be proper (?)