-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Labels
recipeRecipe RequestedRecipe Requested
Description
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
- 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);
-}Any additional context
As discovered working through
ppkarwasz
Metadata
Metadata
Assignees
Labels
recipeRecipe RequestedRecipe Requested
Type
Projects
Status
Recipes Wanted