Inspectopedia Help

Number of placeholders does not match number of arguments in logging call

Reports SLF4J, Log4j2 and akka.event.LoggingAdapter logging calls, such as logger.info("{}: {}", key) where the number of {} placeholders in the logger message doesn't match the number of other arguments to the logging call.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

LoggingPlaceholderCountMatchesArgumentCount
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | JVM languages | Logging

Use the inspection option to specify which implementation SLF4J uses. If Check automatically is chosen, then org.apache.logging.slf4j.Log4jLogger is searched in the classpath. If this file is founded or Yes is chosen, then cases, when the last parameter with an exception type has a placeholder, will not be reported for SLFJ4 API.

For example:

//this case will not be reported with "Yes" option log.error("For id {}: {}", "1", new RuntimeException());

In this case 'new RuntimeException()' will be printed using 'toString()', (its stacktrace will not be printed):

For id 1: java.lang.RuntimeException

Otherwise, it will be highlighted because the last placeholder is not used:

For id 1: {} java.lang.RuntimeException: null

No option can be used to always highlight such cases when a placeholder is used for an exception even if org.apache.logging.slf4j.Log4jLogger is used as a backend. This option works only for SLF4J.

Inspection options

Here you can find the description of settings available for the Number of placeholders does not match number of arguments in logging call inspection, and the reference of their default values.

SLF4J uses Log4j 2 as implementation

Default setting: Check automatically

Other available settings:

  • No

  • Yes

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024