Files
openide/java/java-impl/resources/inspectionDescriptions/StringConcatenationArgumentToLogCall.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

38 lines
1.3 KiB
HTML

<html>
<body>
Reports non-constant string concatenations that are used as arguments to <b>SLF4J</b> and <b>Log4j 2</b> 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.
<p><b>Example:</b></p>
<pre><code>
<b>public class</b> Vital {
<b>private static final</b> Logger LOG = LoggerFactory.getLogger(Vital.class);
<b>public void</b> saveTheWorld(<b>int</b> i, String s, <b>boolean</b> b) {
LOG.info("saveTheWorld(" + i + ", " + s + ", " + b + ")");
// todo
}
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
<b>public class</b> Vital {
<b>private static final</b> Logger LOG = LoggerFactory.getLogger(Vital.class);
<b>public void</b> saveTheWorld(<b>int</b> i, String s, <b>boolean</b> b) {
LOG.info("saveTheWorld({}, {}, {})", i, s, b);
// todo
}
}
</code></pre>
<!-- tooltip end -->
<p>
Configure the inspection:
</p>
<ul>
<li>
Use the <b>Warn on</b> list to ignore certain higher logging levels. Higher logging levels may be enabled even in production, and the arguments will always be evaluated.
</li>
</ul>
</body>
</html>