Logger eagerly evaluates the message before checking the log level
Closed this issue · 1 comments
kamilkloch commented
With log level set to INFO
, the following snippet
logger.debug({ println("this should not be printed"); ""})
prints
this should not be printed
This is arguably an undesired behavior. Compare with https://github.com/lightbend-labs/scala-logging, where you can call log methods, without checking whether the respective log level is enabled.
wsargent commented
The first argument is an argument template, which takes a static string -- if you want to render an argument as the only thing in the template, you would typically do it using logger.debug("{}", Arguments("foo"))
.
You can use lazy blocks for preference:
logger.debug { debug =>
val debugInfo = ...
debug(st"I am a debugging statement with lots of extra $debugInfo")
}