-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[java] GuardLogStatement can have more detailed example #3144
Copy link
Copy link
Closed
Labels
an:enhancementAn improvement on existing features / rulesAn improvement on existing features / rulesin:documentationAffects the documentation [doc]Affects the documentation [doc]
Milestone
Description
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.
- ... (e.g. if you're using maven:
mvn clean verify) - ...
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
an:enhancementAn improvement on existing features / rulesAn improvement on existing features / rulesin:documentationAffects the documentation [doc]Affects the documentation [doc]