Proposal: make module of Logger callsite available in Logger metadata

38 views
Skip to first unread message

Myron Marston

unread,
Oct 4, 2016, 12:35:17 PM10/4/16
to elixir-lang-core

On the main Elixir project I work on, I’ve found that the log messages we naturally write tend to lack sufficient context to identify where in the application the message comes from. For example:

Logger.warn("Extra metadata lines found while only expecting one: #{inspect rest}")

In the context of our application, there are a number of places this could come from. When we see it in our logs, we can of course search our source code to find where it came from, but I’ve gotten in the habit of prepending the module to my log messages so the context is clear:

Logger.warn("#{__MODULE__}: Extra metadata lines found while only expecting one: #{inspect rest}")

At this point, it would be simpler (and more consistent) if the module was available in Logger metadata — then we could just configure it to always be included in every log message, and not have to manually add it to each one.

So, my proposal is for Elixir to make the module available in Logger metadata, so folks who want it included in every log message (like us) can configure it to do so. I’m willing to work up a PR to add support for this if there’s a consensus reached to add it. If we do add it, we should decide what to call the metadata key. :module is simple, but perhaps isn’t intuitively obvious what it means. Maybe :callsite_module (or similar) would be better? I’m not sure.

Thanks,
Myron

José Valim

unread,
Oct 4, 2016, 12:54:11 PM10/4/16
to elixir-l...@googlegroups.com
I believe both modules and functions are part of the metadata already. If not, they should be. So +1.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9841f8fe-9776-4d69-9874-890d0f8502d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--


José Valim
Skype: jv.ptec
Founder and Director of R&D

Myron Marston

unread,
Oct 4, 2016, 12:56:44 PM10/4/16
to elixir-lang-core
You are correct -- it's already available!  Somehow I missed that when I read the docs before.  Thanks, José :).


--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/Ij2NxhZquCI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LvtSA8aOSZbtKriB%2Bq6%2BL3sUhZyG78QzBOpzKua_CnMw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages