How can I see log metadata in dev?

So to summarize, just having this in your application.ex:

:logger.update_formatter_config(:default, %{metadata: [:your_metadata_key]})

…is enough. You don’t have to touch any of the configs in the config/ directory at all.

And you can just do this after:

Logger.info("stuff", your_metadata_key: other_stuff)

And it will be shown.

And when your metadata is not a primitive value (let’s not argue if string is a primitive, please :smiley:) then you should either JSON encode it, or just inspect it (which turns it into a string that you can just paste in iex most of the time).

So yeah, that’s that. Huge thanks to @LostKobrakai and @ibarch.


I have to say that I am disappointed. This is an implicit behavior that I expected to at least have Logger complain about. It instead silently rejects stuff. :confused: I believe there’s a niche to be served in the Elixir ecosystem by custom Logger formatters, and probably an even bigger niche to just be able to configure Logger on maximum two places (compile + boot time config, and runtime config) and have zero surprises – which must include complaints if you pass it objects it would otherwise ignore.

Writing this down as one of my Elixir grievances. Might be able to tackle it OneDay™.