I came from Java world and in Java we used to test if debug is enabled before logging with level debug. Something like this:
if(logger.isDebugEnabled)
logger.debug("Debug")
This is in order to avoid evaluation of arguments passed into logger.debug. Do we have to do the same with scala LazyLogging trait?
class Test extends LazyLogging{
val veryBigSeq: Seq[String] = //...
logger.debug(veryBigSeq.toString()) //<<----- Here
}
As you can see, the code
if(logger.isDebugEnabled)
logger.debug("Debug")
is pretty repetitive, and can easily be generated automatically just from the part of the AST that is passed as an argument to logger.debug(...). It would be surprising if this wasn't implemented as a macro. Indeed, if you take a look at the actual code in Logger.scala, then you will see that all those .debug and .error methods are actually macros. Therefore, all the boilerplate will be added automatically, no if-s around each .debug are required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With