You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In SLF4J 2, which is a very common and widespread java logging facade api, there are functions that are meant to fluently create new logging statements. https://www.slf4j.org/api/org/slf4j/Logger.html see atDebug, atError, atWarning, atInfo, atTrace, atLevel
Those are very convenient, and allow to use closures to compute what to display only if the message has to be logged.
Common usage is like:
logger.atError().setMessage("some message with two arguments {} ms: {}")
.addArgument("some string argument")
.addArgument(() -> System.currentTimeMillis() - startDate)
.log();
A very common error is to forget the ending log() call.
With code like:
logger.atError().setMessage("some message with two arguments {} ms: {}")
.addArgument("some string argument")
.addArgument(() -> System.currentTimeMillis() - startDate);
you can spend an enormous amount of time wondering why your expected logging statement is not in the output.
If PMD could detect that the org.slf4j.spi.LoggingEventBuilder returned by the last addArgument() is neither used by log() nor stored in a variable, we could catch this kind of errors before runtime.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
In SLF4J 2, which is a very common and widespread java logging facade api, there are functions that are meant to fluently create new logging statements.
https://www.slf4j.org/api/org/slf4j/Logger.html see atDebug, atError, atWarning, atInfo, atTrace, atLevel
Those are very convenient, and allow to use closures to compute what to display only if the message has to be logged.
Common usage is like:
A very common error is to forget the ending
log()
call.With code like:
you can spend an enormous amount of time wondering why your expected logging statement is not in the output.
If PMD could detect that the
org.slf4j.spi.LoggingEventBuilder
returned by the lastaddArgument()
is neither used bylog()
nor stored in a variable, we could catch this kind of errors before runtime.Beta Was this translation helpful? Give feedback.
All reactions