This is based on previous conversation in 
https://groups.google.com/d/msg/elixir-lang-core/C5-ixZVau3U/Gkb4PyOOAQAJ, 
but this thread proposes an actual solution which I believe will benefit 
everyone.

The Logger in Elixir is widely used due to being in the standard library, 
but misses out on a few key use cases that are familiar for developers 
coming from other languages. For one, I believe it's time to add 
functionality to suppress logs on a per-application basis. As the 
application is known to the logging macros it can easily filter out at 
compile time. This can also be a backwards-compatible option inside the 
Logger configuration to override the default log level on a per application 
basis:


config :logger, :my_logger,
  level: :info,
  applications: [
    library1: :debug
  ]


This allows developers to allow logs to be noisier for specific 
applications (such as their own), without being swamped with noise from 
other applications. The :applications key will just override the default 
level provided in the :level key. If the :applications key is not ideal, we 
can name it something else (:apps, :override, etc). We could even just 
combine the two in :levels and use a :default for the default level.

In addition to these changes, I propose that a new logging level be added 
which is lower than the default log level of :debug, with the intent that 
all developers log to this unless there is explicit reason to have their 
logs seen by default. The combination of this and the above :applications 
key allows developers to easily turn on logs from applications they're 
interested in at the time. It allows the application developer to decide 
what is important enough for another developer to see, rather than the 
developer having to (typically) guess. I propose that this new logging 
level should be named any of :trace, :verbose or :quiet (with :trace being 
preferred for brevity/familiarity). 

There are many other languages which encourage this style of logging. Here 
are a few I know of:

- Node.js has the "debug" package, which is widely popular as it allows 
users to opt-in to seeing logs from specific namespaces (which roughly 
translates to OTP applications in our use case). 
- Java has SLF4J which hides debug logs by default, allowing you to opt in 
on package or class level (also hugely popular).
- Rust's official logging framework defaults to actually hiding all 
logging, making you explicitly ask to see logs (of any kind).

The interesting thing with the packages from Node.s/Java is that they're 
libraries and not in the standard library; they evolved because of the 
standard logging missing this stuff (although to be fair, Node.js only has 
console). As the Logger is so widely used in Elixir, it feels that we're 
already at the point where this should be supported. Making this an 
external library in Elixir would be wasted effort as we would then have 
logging from different sources with different behaviour, thus lowering the 
utility. I think that including this support in Logger will make logging 
feel more familiar to developers coming from the languages above, without 
making it unfamiliar to (e.g.) Ruby developers where the behaviour matches 
what Elixir currently has.

I appreciate any support and/or suggestions with this. I feel strongly 
about not having a "quiet" log level, as it causes a very painful balance 
for a library developer when determining how verbose to be with logging.

Thanks in advance for all replies, feel free to ask questions!
IW

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/606029ea-9855-44c6-ba94-69113ffed45c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to