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
Loglevel guards ( such as if (LOG.isDebugEnabled())) are a performance improvement to prevent building up logging statement arguments when the log line would be discarded. Parameterized logging is a similar approach at limiting the impact of logging on performance, by only formatting the logging statement when the loglevel is enabled. Code should likely only have to use one of the two approaches: either loglevel guards, or parameterized logging. So when paramterized logging statements are used, the loglevel guards can be removed.
What precondition(s) should be checked before applying this recipe?
The loglevel guard should only be removed if
all statements in the body are logging statements
all logging statements have arguments that are not method invocations (maybe allow Exception.getMessage()), to prevent side effects
Describe the situation before applying the recipe
if (LOG.isDebugEnabled()) {
LOG.debug("Swallowed an IOException caused by client connectivity: {}", cause.getMessage(), cause);
}
Describe the situation after applying the recipe
-if (LOG.isDebugEnabled()) {- LOG.debug("Swallowed an IOException caused by client connectivity: {}", cause.getMessage(), cause);+LOG.debug("Swallowed an IOException caused by client connectivity: {}", cause.getMessage(), cause);-}
What problem are you trying to solve?
Loglevel guards ( such as
if (LOG.isDebugEnabled())
) are a performance improvement to prevent building up logging statement arguments when the log line would be discarded. Parameterized logging is a similar approach at limiting the impact of logging on performance, by only formatting the logging statement when the loglevel is enabled. Code should likely only have to use one of the two approaches: either loglevel guards, or parameterized logging. So when paramterized logging statements are used, the loglevel guards can be removed.What precondition(s) should be checked before applying this recipe?
The loglevel guard should only be removed if
Exception.getMessage()
), to prevent side effectsDescribe the situation before applying the recipe
Describe the situation after applying the recipe
Any additional context
As discovered working through
The text was updated successfully, but these errors were encountered: