Inspectopedia
 
2024.3

Non-constant string concatenation as argument to logging call

Info
New
Last modified: 03 December 2024

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:

After the quick-fix is applied:

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.