sezaru
Sometimes I get some errors in my log that doesn’t have enough information to allow me to reproduce the issue.
So I was wondering how can I add custom metadata to a process so when a new error is logged, that metadata is show too.
I know that you can do something like this with Logger.metadata, but AFAIK, this only works with structured data, basically you define in the config the keys you accept as metadata and that is what I you can use in all your project.
What I want is to be able to add custom data depending on what I’m doing. For example, if I’m processing some data from a crypto market like BTC_USDT, then I would like my log to show something like market: BTC_USDT when an error is logged.
In other words, I don’t want to have to fill the metadata config with a bunch of keys for every time I want to add a new metadata in my codebase.
config :logger, :console,
metadata: [...]
Trending in Questions
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
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sezaru
I think I figured it out.
What I did was add a
:otherfield to my metadata array, then i adde a case for my custom log formatter to handle that field.So my config became like this:
And my formatter like this:
That way, I can send any data to it using the
othermetadata,For example,
Logger.error("blibs", other: %{blibs: 2})will be logged as:axelson
You can also set
metadata: :allto log whatever metadata you pass.