SLF4J
and Log4j 2
logging methods.
Non-constant concatenations are evaluated at runtime even when the logging message is not logged; this can negatively impact performance.
It is recommended to use a parameterized log message instead, which will not be evaluated when logging is disabled.
Example:
public class Vital {
private static final Logger LOG = LoggerFactory.getLogger(Vital.class);
public void saveTheWorld(int i, String s, boolean b) {
LOG.info("saveTheWorld(" + i + ", " + s + ", " + b + ")");
// todo
}
}
After the quick-fix is applied:
public class Vital {
private static final Logger LOG = LoggerFactory.getLogger(Vital.class);
public void saveTheWorld(int i, String s, boolean b) {
LOG.info("saveTheWorld({}, {}, {})", i, s, b);
// todo
}
}
Configure the inspection: