chulkilee
Hi all,
Here are several libraries I wrote to do structured logging with logger metadta.
- metadata_logger
- metadata_logger_plug: middleware for plug
- metadata_logger_tesla: middleware for tesla
(There were in different name - now renamed to metadata_logger_* and moved to own github org)
Highlights
- Formatter, not backend; e.g. it doesn’t reimplement console logger backend. Choose your own backend! (or just console)
- Minimal transformation: if you pass struct into metadata, it won’t convert it to map blindl; this is to prevent from leaking data into logs by accident. It uses Jason

- Return IO data (not building a large binary!)
See also
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
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
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
As you correctly pointed to my post on the forum with call for testers I need to make few statements:
Loggerwhere metadata and “log message” (or, as called by Erlang, report) will be possible without any wrappers (#9465)Additionally your
metadata_logger_plugis currently more or less possible viaPlug.TelemetryAPI, which I believe is currently more standardised and commonly supported (ex.Phoenix.Loggeruses that).However, nice work and I really appreciate idea of bringing structured logging to Elixir.
chulkilee
Thanks! I know there are lots of work going on logging and telemetry (which can be used for logging as well).
Here are my takes:
Log formatter will remain - just in different form: seems like new erlang logger (21.1) has log_formatter and Elixir is planning to use same mechanism so that elixir and erlang use same log event, and leverage same logging backend (via passing handler_config)
Metadata will be a map - I think this is the right way to go, as erlang already uses map ref (and it’s planned in #7928)
Passing map as a message is planned but it won’t invalidate use of metadata - passing a map as a message is planned in #9465. However, I see metadata is for scope-based while map message is for per message - and I found both are needed when I’m using them.
Note that this can be done even in the current Elixir if you use formatter taking a map message
See this PR I just wrote…
instrumentation logging via :telemetry - I really like that idea! Plug.Telemetry was added after I wrote this middleware
I created issues: for plug and for tesla
hauleth
I am fully aware of the implementation and future plans, I made both of them
Yes, but the plan is to make it Erlang logger formatter, as you have noticed.
Internally, yes, from the user viewpoint, no. This is required for the compatibility. So in Elixir 1.10 it will be changed before returning in
Logger.metadata/0.Yes, as metadata is for something completely different. Using your example in
metadata_logger_plugthe status, body length, and response status should be part of the report, not metadata. Metadata is more about, well, meta data like: version, log position, module, function, application name, etc.Well, partially. It will work for that particular formatter, but in general it will fail (also Dialyzer will complain) as you break contract about type of the accepted data. So that single formatter will work (because it relies on undefined behaviour), but any other will fail, and this will fail with parsing Erlang reports, as these are handled before these end in your translator.
chulkilee
I think we’re pretty on the same page! Thanks a lot for follow-ups
I created a placeholder issue
Note on “metadata” being metadata.
That’s right for plug case (I’m putting them into metadata only because it’s only places I can put there for now).
However, please note that applications often need process-scoped logging data - such as plug request id - to group log messages with them later. For example, as I put them in (elixir) logger metadata (which is set in process), I can easily see all logs for a plug request.
Do I need to pass that “request id” to all functions which may produce logs? I don’t think that’s practical - and I believe that’s perfect use case of process-level information. As logger metadata is process-level - I’m just using that for process-level data.
Unfortunately, that leads to mix of runtime/language-specific metadata with application data - but Erlang itself even use metadata to carry not only event-specific info (e.g. file, line) and some configuration (e.g.
report_cb)Or do we want separate set of funcs and keep them separately and do not mix “metadata” of runtime and “process-level application data”? That’s possible - but I don’t think the current logger metadata discourage use of metadata for such use..
(I believe I brought up this somewhere, but I cannot remember..)
hauleth
No, because
request idisn’t part of the log message, it is part of the context for the log message. This is huge difference that I am pointing there. Erlang logger also makes these difference as there are separate. If I would need to define in short the difference then I would say:Responded with OK 200 in 532ms (1 KiB)or%{http_response_code: 200, http_response_time: 532_000, http_body_size: 1024})line: 42, mfa: {Foo.Controllers.Users, :show, 2}, time: 1573853293025234000, pid: #PID<0.108.0>), additionally it will contain all “meta” stuff, like mentionedreport_cbSo you do not mix metadata and log data, and you do not need to pass some metadata to each execution. How it is presented later is completely different thing. Some tools make it even more distinct (for example Grafana’s Loki) as metadata are indexed, so these shouldn’t vary too much to not bloat indices, while data is not parsed at all.
And this is a little bit of the problem, as such data do not belong to the “metadata”, as this is data (without “meta” part). Fortunately in near future this will change.