Debug log in Scala with no performance impact
debugging, logging, optimization, preprocessor, scala
Solution
You can use `scala.annotation.elidable`
An annotation for methods for which invocations might be removed in the generated code.
Behavior is influenced by passing -Xelide-below to scalac. Methods marked elidable will be omitted from generated code if the priority given the annotation is lower than to the command line argument. Examples:
Problem
In languages like C/C++/Objective-C it's common to use preprocessor macros to define logging mechanisms that are not even compiled for released binaries, thus causing no performance hit. Something along the lines of: ``` #ifdef DEBUG printf("some event we want to log\n"); #endif ``` Now, I know there's no preprocessor in Scala. So my question is: what is the best way to implement a mechanism to log program activity for debug purposes, while impacting performance the least when it's turned off?