hauleth
As some of you are aware (and the rest will be if they read this post) the OTP 21 introduced new logger module which provides real-life logger to the Erlang itself. For a long time (I think that Elixir 1.7 was the first one with integration) Elixir was hooking into it to listen for messages sent by Erlang libraries, but it was only one way integration (so messages sent by Elixir wasn’t available to Erlang handlers).
But it is no more, as PR 9333 was merged to the master, now Logger is a thin wrapper over Erlang’s built in functionality with compatibility layer on top to support all backends that already are there.
However that one is a huge change and I with @josevalim were working on it for over a month to find all problems and provide good implementation. We are pretty confident with the implementation, but nothing is better than testing in production. So this is time for all of You, embrace your fears and boldly go where no one has gone before. We need You to test it with your applications (of course locally, we do not encourage anyone to test it in real production).
Please, test it, break it, report it.
For those who are interested in “what it will give us anyway?”:
- Unified metadata between loggers (and potentially other libraries like
opentelemetry) - Out of the box integration with Lager as Lager hooks into
loggeras well - Built in support for logging to disk via
logger_disk_log_h
These are for now, in future the changes will include:
- Additional log levels (
notice,critical,alert,emergency) - Support for structured logging
- Module and application level control about logs verbosity
But anyway, play with it, test it, and if you break it, let us know so we can polish it before final release of 1.10 (oh, by the way this will make Elixir 1.10 OTP 21+ only).
Trending in Discussions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sneako
Thanks for these contributions! I installed elixir master using asdf:
asdf install elixir ref:67dec4683de49e6e8153f9c49d0a0a179c550f9fand gave it a try in a phoenix app where I have:
config :logger, level: :warnAnd I get:
So the first thing to note is that the log level
:warnis deprecated, but is there also a new way to configure the log level?Trying
level: :infoorlevel: :warningproduce a similar warning, but no match error, and logging seems to work as usual.hauleth
Yeah, it seems like there is first bug
Thanks
The point is that
:warnused by Elixir Logger is now:warningform the Erlang, but there should be translation from old format to the new format. This was done, but in the meantime we have changed code a little to provide given message, and the translation perished. Will provide fix in a moment.Ninigi
Thank you! This was bugging me in Rails apps for a long time. Why would you set the debugger level to
warnif the output level wasWARNING…I think this is a very nice addition, but for my own sake, can you make sure to notify AppSignal about this? Maybe they already know, maybe they don’t care… I just don’t want to end up with unnecessary errors on that platform.
Thank you very much for everything (even though I curse you for introducing
drab, no fun upgrading a phoenix app)EDIT: as @hauleth has made clear, I mistook him for the creator of drab. @grych . Really sorry about the mix up, ignore what I said about drab.
hauleth
They do not need about it, as the API is backward compatible, so if they are registering their own Logger backend (Elixir one) then nothing will change. They would need to use Erlang handler instead, but currently writing them isn’t so straightforward as Elixir ones (you need to prevent overload on your own, as Erlang logger do not handle it for you).
I do not get that as I haven’t worked on
drab, I didn’t even used it even once in my life.Ninigi
Oh, so sorry! your avatar looks like the other one on my tiny laptop screen… Really sorry, I mistook you for someone else.
Ninigi
They provide a plug for Phoenix, and modules to do your own error messages, I was just wondering if they might be affected by this
But you know what, I will shoot them a message, maybe they can improve their logging based on this
dom
Very excited about this. Thanks for all your work!
I’m curious what approach you have in mind for structured logging. So far I’ve been doing it this way:
add_metadatareads each key/value pair frommetadata, converts the value to a printable representation, and adds it to the event map, similar to Honeybadger.JSON.It works, but it’s not ideal - we had to reimplement functionality from the default formatter, for instance formatting time or converting PIDs to strings. OTP reports also can’t be structured, because they’re a string blob by the time they reach the formatter (not a huge deal though).
Could we achieve JSON logging more easily with the new backend, or with future development?
hauleth
Partially yes, and yes.
Elixir’s
Loggercurrently do not expose API for structured logging, but as these two are integrated, you are free to use ErlangloggerAPI directly, which does support that. The API is pretty simple and in your case it would be:The problem with this approach is that you still do not have direct access to the report (as it is called) in Elixir backend nor formatter, as these will receive message already changed to string. So in this situation you have 2 possible approaches:
The 1st approach is IMHO much more foolproof and should be simpler to manage in future (unless you are using custom backend for Elixir, but from what I see, you log to disk, and Erlang logger provides 2 handlers for that
logger_std_handlogger_disk_log_h).deadtrickster
We can test it, especially if opencensus trace_ids will appear here.
hauleth
It will, as this was partially the reason to do such. This integrates the Erlang and Elixir process metadata, so it will be perfectly reasonable and possible to set such data in one place only.