A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3144 below:

[java] GuardLogStatement can have more detailed example · Issue #3144 · pmd/pmd · GitHub

Affects PMD Version:
6.31

Rule: GuardLogStatement

Description:

GuardLogStatement says that you should check for logLevel or do not check for logLevel but do not create String via concatenation. It would be useful to have one more example on how to avoid if statement and to use lazy logging
for log4j2 or slf4j working with parameters

Whenever using a log level, one should check if the loglevel is actually enabled, or
otherwise skip the associate String creation and manipulation.
EXAMPLE:
    // Add this for performance
    if (log.isDebugEnabled() { ...
        log.debug("log something" + " and " + "concat strings");

Exception Stacktrace:

# Copy-paste the stack trace here

Code Sample demonstrating the issue:

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. ... (e.g. if you're using maven: mvn clean verify)
  2. ...

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4