[Proposal] Logger.put_process_level/2

69 views
Skip to first unread message

Stefan Chrobot

unread,
Mar 1, 2022, 7:11:52 AM3/1/22
to elixir-l...@googlegroups.com
Hi, I'd like to propose an addition of put_process_level(pid, level) into the Logger module to allow controlling the runtime logging level on a per-process basis.

Our app runs multiple background processing jobs that are performing data sync. This means that the jobs run "forever". We're running a job (OTP process) for each user. While we have metrics and alerts to understand when a new user is hitting some bumps, we'd like to have detailed logs to help debug any potential issues. The issues are mostly data-dependent and are happening in the initial phase of the sync. After that, the issues rarely ever happen and so the detailed logs are pretty useless, but they still consume resources.

We could address our use case with something like the following:

new? = DateTime.diff(DateTime.utc_now(), sync_start) > @threshold
Logger.put_process_level(self(), if new?, do: :debug, else: :warn)

The implementation should be pretty straightforward and resemble the implementation of Logger.enable/1.

Looking forward to your thoughts.


Best,
Stefan

José Valim

unread,
Mar 1, 2022, 7:18:16 AM3/1/22
to elixir-lang-core
Sounds good to me, a PR is welcome! We should actually change Logger.enable to use the new Logger.put_process_level, especially because we have two meta-levels called :none and :all.

--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CACzMe7YxiOYc9esU68Db%2Bq7zwfixg2cJyYwb5X2tXdj6V52efw%40mail.gmail.com.

Stefan Chrobot

unread,
Mar 1, 2022, 7:21:01 AM3/1/22
to elixir-l...@googlegroups.com

luk...@niemier.pl

unread,
May 28, 2022, 6:16:33 AM5/28/22
to elixir-lang-core
There was discussion about that in OTP repository. Unfortunately it is not possible with current implementation of logger, as you cannot lower the requirement below default level per process, it is simply not supported by the OTP logger.

José Valim

unread,
May 31, 2022, 6:45:03 AM5/31/22
to elixir-lang-core
Hi Łukasz,

Can you please expand what you mean? We already added Logger.put_process_level/2, which applies only to the current process at the moment. So it seems there is a pitfall we may need to document? I believe a process cannot override the general log level, is that correct? In other words, it can only be used to have a more restricted one.

Thanks!

Reply all
Reply to author
Forward
0 new messages