In my code's package, I have a flag such as:
public static final boolean LOGS_VERBOSE = false;
And in worker classes (multi threaded Runnable
jobs), I have code like:
if(XYConstants.LOGS_VERBOSE){
logger.debug("some state info var 1:" + var1 + ", var 2:" + var2);
Is this a good idea? Is there any performance gain? Developers say it avoids code going to the log4j level completely, and there is hardly any overhead to check the value of the constant.
We do plan to do performance testing, but that is a month away, and I need to show code to the client (who is a developer of 14 years) this Friday. I'm wondering if this should stay or not?
We have some debugs without the boolean check too, and those are wanted in all runs as long as log4j is configured in debug level.
This code is using log4j 1.2.16.
trace()
is not used, considering there are some debug messages that should always be shown (proper debugging?), and there are those with this boolean check (really verbose)? Also, is your team keen to explore switching to an alternative such as SLF4J that can handle these logging more fluently? You get parameterized log messages too. \$\endgroup\$