Enhances logging of exceptions by including the full stack trace in addition to the exception message
org.openrewrite.java.logging.slf4j.CompleteExceptionLoggingorg.openrewrite.recipe:rewrite-logging-frameworksIt is a common mistake to call Exception.getMessage() when passing an exception into a log method. Not all exception types have useful messages, and even if the message is useful this omits the stack trace. Including a complete stack trace of the error along with the exception message in the log allows developers to better understand the context of the exception and identify the source of the error more quickly and accurately.
If the method invocation includes any call to Exception.getMessage() or Exception.getLocalizedMessage() and not an exception is already passed as the last parameter to the log method, then we will append the exception as the last parameter in the log method. Additionally, if an exception is passed directly as a format argument that fills a {} placeholder, the placeholder is removed so that the exception is treated as the trailing argument, ensuring the full stack trace is logged.
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.logging.slf4j.CompleteExceptionLoggingIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-logging-frameworks:3.31.0Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats