Inspectopedia Help

Non-constant string concatenation as argument to logging call

Reports non-constant string concatenations that are used as arguments to 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:

  • Use the Warn on list to ignore certain higher logging levels. Higher logging levels may be enabled even in production, and the arguments will always be evaluated.

Inspection options

Here you can find the description of settings available for the Non-constant string concatenation as argument to logging call inspection, and the reference of their default values.

Warn on

Default setting: all log levels

Other available settings:

  • warn level and lower

  • info level and lower

  • debug level and lower

  • trace level

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024