quinta-feira, 16 de agosto de 2012

log4j performance

Aiming better performance, in log4j 1.2 [1], you can use:
if(logger.isDebugEnabled() {
    logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
}
instead
logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
In log4j 2 [2], you can use the new feature
logger.debug("Entry number: {} is {}", i, entry[i]);

References

[1] http://logging.apache.org/log4j/1.2/manual.html
[2] http://logging.apache.org/log4j/2.x/performance.html