First of all, bow to @Shadowlands, @ArneClaassen and @OlgeRudenko. As mentioned in the comments, this seems like a known issue. This prevented me from trying to βsolveβ it. The next thing to do was find a good job that didn't break Scala's idioms.
Given these limitations, I decided to go with String Interpolation , as suggested above. I also switched to scala-logging . Quote from their github / readme,
Scala Registration is a convenient and efficient SLF4J journal registration library. This is convenient because you can simply call the log methods without checking if the appropriate log level is enabled:
logger.debug (s "Some expensive message!")
This works because the Scala macros use the check-enabled-idiom function, as well as writing this more involved code:
if (logger.isDebugEnabled) logger.debug (s "Some expensive message!")
Thanks everyone! As far as I know, this is allowed. If commentators can post their answers, I will be happy to acknowledge them.
As always, feel good on the shoulders of friendly giants!
PS: I just checked that there is no execution cost for String interpolation if you use scala -logging . My verification method was raw but effective.
log.debug{ { throw new IllegalAccessException("This should not have been called with debug off!") } s"Added Header ${name}:${headerValue}" }
Of course, when I set my log to DEBUG , an exception is thrown as expected, but disappears when I set it to a higher level. And yes, I already deleted the IllegalAccessException part :).