dimitarvp
EDIT: There has been back and forth and I was impatient, operating under the assumption that I am missing something obvious and small. Turns out it wasn’t exactly that. I accepted @LostKobrakai’s comment because it showed me how exactly to configure Logger metadata at runtime, but it was @ibarch’s comment near the end that finally made it work (because apparently Logger ignores “complex” metadata so you have to either do Jason.encode!(metadata) or inspect(metadata).
I have failed the 5-minute test of finding what I need. ![]()
So I have this code somewhere in my app:
Logger.error("Invalid payload", payload: message)
I copied my default Logger config to config/dev.exs:
config :logger, :console,
format: "$time $level $metadata $message\n",
metadata: [:request_id]
So I call the function with an invalid parameter and all I see is this:
15:54:12.439 error Invalid payload
No metadata. Tried with info just in case, same result. What should be changed?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #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
- #elixirconf-us
- #blog-post
- #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)
Schultzer
The issue might be that you only including the request_id in the metadata, Logger — Logger v1.20.2 I believe thats why the payload is excluded and was one of the reason that I scraped including capturing logger in https://dbvisor.com that is leveraging telemetry and storing them in a timeseries table in your DB for easy debugging.
dimitarvp
Removed the metadata part of the config, nothing changed sadly.
Also migrated the config to this:
And again, no metadata.
To respond to the second half of your message, production logging and telemetry is yet to be decided but in the meantime I just want to see the metadata on my machine while testing.
Schultzer
I feel there must be a place that is overriding this. Did you try to print out the config like IO.inspect Application.get_env(:logger)
linusdm
Aren’t you missing the
:payloadvalue under the metadata config option?dimitarvp
Didn’t realize metadata was strictly opt-in, OK, included it:
Still nothing.
dimitarvp
If anybody wants to play with this before we solve it, here’s a self-contained script that demonstrates my problem (mine is called
logging_playground.exs):Then just
elixir logging_playground.exsand you should see no metadata, only this:linusdm
It doesn’t honor the format either (it still adds the square brackets), so it doesn’t pick up on the whole config.
dimitarvp
Yep, now that you mention it, quite interesting actually.
Schultzer
Weird, might be easier to just use telemetry and setup your own handler to print to the console on dev. Then you also gain way more control then Logger could give you.
dimitarvp
Maybe, but I’d be hugely surprised if Elixir doesn’t cover this use case trivially. I must be having a Saturday afternoon moment here and missing something extremely obvious.