How Scala Logging handles string interpolation
mainScala Logging uses macros to transform idiomatic Scala string interpolation (e.g., logger.error(s"msg $arg")) into efficient SLF4J parameterized logging (e.g., logger.error("msg {}", arg)). This ensures that expensive string construction only happens if the log level is enabled.
Limitations:
- This transformation only works when string interpolation is used directly inside the logging statement (the message must be static at compile time).
- It does not work when you are logging an exception alongside string interpolation (due to SLF4J API limitations).
// Idiomatic Scala (transformed to SLF4J style by macros)
logger.error(s"my log message: $arg1 $arg2 $arg3")
// Resulting SLF4J call
logger.error("my log message: {} {} {}", arg1, arg2, arg3)