Add global metadata to the Logger

Hi all :wave:
I’d like to add some information to the Logger metadata “globally”, in the sense that every logged message will include it.

Do you know if it is possible to configure the Logger to achieve that? (I’m on Elixir 1.11.4, Erlang/OTP 24)

I searched in the documentation but I couldn’t find anything about and I remember that I have read somewhere that this should have been possible with the latest OTP release.

Thanks :blush:

Well, it isn’t promoted enough, but yes, since OTP 24 you can have global metadata. It is not exposed via Logger because we still need to support OTP 22-23, but it is possible to use today:

:logger.update_primary_config(%{metadata: %{foo: :bar}})

Beware that metadata there must be a map.


Ohhh wonderful! thank you so much @hauleth :bowing_man:
It works great!