-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Labels
enhancementNew feature or requestNew feature or request
Description
What problem are you trying to solve?
When logging exceptions using SLF4J or Log4j API, a common mistake is to add a placeholder for the exception in the message format:
try {
...
} catch (Exception e) {
log.error("An error occurred: {}", e);
}
Describe the solution you'd like
Currently there is a CompleteExceptionLogging rewrite rule that deals with the case:
try {
...
} catch (Exception e) {
log.error("An error occurred: {}", e.getMessage());
}
This rule could be expanded to rewrite the first example into either:
try {
...
} catch (Exception e) {
log.error("An error occurred:", e);
}
or
try {
...
} catch (Exception e) {
log.error("An error occurred: {}", e.getMessage(), e);
}
Have you considered any alternatives or workarounds?
Palantir already offers a LoggerInterpolationConsumesThrowable Error Prone rule, that could be expanded to generate a code change suggestion.
Are you interested in contributing this feature to OpenRewrite?
Right now I don't have time for the OpenRewrite rules already assigned to me. If this is not solved till September, I can provide a PR.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
Backlog