[erlang-questions] proper way to use the new logger

Siri Hansen erlangsiri@REDACTED
Mon Sep 3 15:44:11 CEST 2018


Hi Nicolas,

to set the module level in configuration, use the kernel parameter
'logger', and the term {module_level,Level,Modules}, for example, to set
debug level for modules x, y and z:

sys.config:
[{kernel,[{logger,[{module_level,debug,[x,y,z]}]}]}].

Note that you must use the log macros for logging for this to work. Or,
alternatively, add mfa=>{Module,Function,Arity} to the metadata for each
log event.

Unfortunately, there is no built-in way to get the module name only into
each log message, but if you use the marcos (or add mfa yourself) you can
get Module:Fun/Arity in your log messages by adding the atom 'mfa' to your
formatter template, e.g.

1> logger:update_formatter_config(default,template,[time," ",level,",
",mfa,": ",msg,"\n"]).
ok
2> logger:debug("hello world",#{mfa=>{x,f,1}}).
2018-09-03T15:37:35.577776+02:00 debug, x:f/1: hello world

BR
/siri


Den ons. 29. aug. 2018 kl. 18:07 skrev Nicolas Martyanoff <khaelin@REDACTED
>:

> Hi,
>
> I have been trying to use the new logger application, and I am not sure
> about
> the way I am supposed to configure it for my needs (keep in mind that I am
> an
> Erlang beginner, hoping to use Erlang in production someday).
>
> During development of a "library", i.e. an OTP application used by the
> program
> I am working on, I need to see all logs related to the modules which are
> part
> of the OTP application. However I cannot see how to set the log level to
> `debug` for these modules only (and not globally with `{logger_level,
> debug}`). Ideally, there would be a way to configure it in a local
> sys.config
> to get this effect only during development, without having to do it
> programmatically in every module I work on.
>
> More importantly, I can't seem to find a way to include the name of the
> module
> in log messages, either in the formatter template or anywhere else. Am I
> supposed to add it manually to every single logger message I write ?
>
> I am just trying to find a simple way to add log instructions to the code I
> write, with the possibility to control which ones are printed depending on
> the
> environment (local library development, application development, tests,
> production...) using settings in sys.config.
>
> Thank you in advance.
>
> --
> Nicolas Martyanoff
> http://snowsyn.net
> khaelin@REDACTED
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180903/32e2d251/attachment.htm>


More information about the erlang-questions mailing list