user3644708
user3644708

Reputation: 2495

How to only log when in debug mode using erlang-lager?

In Java Development, we did debug checking before logging a time / memory consuming operation.

for example:

if(log.isDebugEnabled()){
   log.debug("This is time / memory consuming {}", bigString);
}

with Erlang Lager, Do I need to do the same check before logging it?

If yes, how to check this?

Upvotes: 1

Views: 576

Answers (1)

Lol4t0
Lol4t0

Reputation: 12557

With lager, you can change desired log level with lager configuration, so you can omit any check in the code. If debug level is not enabled for any backend, it will be just dropped

See example

{lager, [
  {log_root, "/var/log/hello"},
  {handlers, [
    {lager_console_backend, info},
    {lager_file_backend, [{file, "error.log"}, {level, error}]},
    {lager_file_backend, [{file, "console.log"}, {level, info}]}
    {lager_file_backend, [{file, "debug.log"}, {level, debug}]}
  ]}
]}.

So debug logs will only go to debug.log

Upvotes: 1

Related Questions