Files
gh-openrewrite-rewrite-docs…/skills/writing-openrewrite-recipes/references/recipes-logging-common.csv
2025-11-30 08:45:33 +08:00

14 KiB

1Fully Qualified Recipe NameRecipe NameDescription
2org.openrewrite.java.logging.containerized.ContainerizeLog4j2PropertiesConfigurationContainerize Log4j2 Properties configurationTransforms Log4j2 Properties configuration to write logs to stdout instead of files suitable for containerized environments.
3org.openrewrite.java.logging.containerized.ContainerizeLog4j2XmlConfigurationContainerize Log4j2 XML configurationTransforms Log4j2 XML configuration to write logs to stdout instead of files suitable for containerized environments.
4org.openrewrite.java.logging.containerized.ContainerizeLog4j2YamlConfigurationContainerize Log4j2 YAML configurationTransforms Log4j2 YAML configuration to write logs to stdout instead of files suitable for containerized environments. (Implementation in progress)
5org.openrewrite.java.logging.containerized.ContainerizeLogbackConfigurationContainerize Logback configurationTransforms Logback XML configuration to write logs to stdout instead of files suitable for containerized environments.
6org.openrewrite.java.logging.containerized.ContainerizeLoggingContainerize logging configurationTransforms logging configurations to write to stdout instead of files making them suitable for containerized environments. This composite recipe applies transformations for multiple logging frameworks including Log4j2 Logback Log4j 1.x and Java Util Logging.
7org.openrewrite.java.logging.containerized.log4j2.ContainerizeLog4j2Containerize Log4j2 configurationTransforms all Log4j2 configuration formats (XML Properties YAML JSON) to write logs to stdout instead of files.
8org.openrewrite.codehaus.plexus.AbstractLogEnabledToSlf4jMigrate from Plexus `AbstractLogEnabled` to SLF4JIntroduce a SLF4J `Logger` field and replace calls to `getLogger()` with calls to the field.
9org.openrewrite.java.logging.ArgumentArrayToVarargsUnpack Logger method `new Object[] {...}` into varargsFor Logger methods that support varargs convert any final explicit `Object[]` arguments into their unpacked values.
10org.openrewrite.java.logging.ChangeLoggersToPrivateChange logger fields to `private`Ensures that logger fields are declared as `private` to encapsulate logging mechanics within the class.
11org.openrewrite.java.logging.ParameterizedLoggingParameterize logging statementsTransform logging statements using concatenation for messages and variables into a parameterized format. For example `logger.info("hi " + userName)` becomes `logger.info("hi {}" userName)`. This can significantly boost performance for messages that otherwise would be assembled with String concatenation. Particularly impactful when the log level is not enabled as no work is done to assemble the message.
12org.openrewrite.java.logging.PrintStackTraceToLogErrorUse logger instead of `printStackTrace()`When a logger is present log exceptions rather than calling `printStackTrace()`.
13org.openrewrite.java.logging.SystemErrToLoggingUse logger instead of `System.err` print statementsReplace `System.err` print statements with a logger.
14org.openrewrite.java.logging.SystemOutToLoggingUse logger instead of `System.out` print statementsReplace `System.out` print statements with a logger.
15org.openrewrite.java.logging.SystemPrintToLoggingUse logger instead of system print statementsReplace `System.out` and `System.err` print statements with a logger.
16org.openrewrite.java.logging.jboss.FormattedArgumentsToVMethodRecipesReplace deprecated JBoss Logging Logger formatted message invocations with the v-version of methodsReplace `logger.level("hello {0}" arg)` with `logger.levelv("hello {0}" arg)`.
17org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelConfigSupplierToMethodRecipeReplace JUL `Logger.log(Level.CONFIG Supplier<String>)` with `Logger.config(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.CONFIG Supplier<String>)` with `Logger.config(Supplier<String>)`.
18org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelConfigToMethodRecipeReplace JUL `Logger.log(Level.CONFIG String)` with `Logger.config(String)`Replace calls to `java.util.logging.Logger.log(Level.CONFIG String)` with `Logger.config(String)`.
19org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelFineSupplierToMethodRecipeReplace JUL `Logger.log(Level.FINE Supplier<String>)` with `Logger.fine(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.FINE Supplier<String>)` with `Logger.fine(Supplier<String>)`.
20org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelFineToMethodRecipeReplace JUL `Logger.log(Level.FINE String)` with `Logger.fine(String)`Replace calls to `java.util.logging.Logger.log(Level.FINE String)` with `Logger.fine(String)`.
21org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelFinerSupplierToMethodRecipeReplace JUL `Logger.log(Level.FINER Supplier<String>)` with `Logger.finer(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.FINER Supplier<String>)` with `Logger.finer(Supplier<String>)`.
22org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelFinerToMethodRecipeReplace JUL `Logger.log(Level.FINER String)` with `Logger.finer(String)`Replace calls to `java.util.logging.Logger.log(Level.FINER String)` with `Logger.finer(String)`.
23org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelFinestSupplierToMethodRecipeReplace JUL `Logger.log(Level.FINEST Supplier<String>)` with `Logger.finest(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.FINEST Supplier<String>)` with `Logger.finest(Supplier<String>)`.
24org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelFinestToMethodRecipeReplace JUL `Logger.log(Level.FINEST String)` with `Logger.finest(String)`Replace calls to `java.util.logging.Logger.log(Level.FINEST String)` with `Logger.finest(String)`.
25org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelInfoSupplierToMethodRecipeReplace JUL `Logger.log(Level.INFO Supplier<String>)` with `Logger.info(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.INFO Supplier<String>)` with `Logger.info(Supplier<String>)`.
26org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelInfoToMethodRecipeReplace JUL `Logger.log(Level.INFO String)` with `Logger.info(String)`Replace calls to `java.util.logging.Logger.log(Level.INFO String)` with `Logger.info(String)`.
27org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelSevereSupplierToMethodRecipeReplace JUL `Logger.log(Level.SEVERE Supplier<String>)` with `Logger.severe(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.SEVERE Supplier<String>)` with `Logger.severe(Supplier<String>)`.
28org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelSevereToMethodRecipeReplace JUL `Logger.log(Level.SEVERE String)` with `Logger.severe(String)`Replace calls to `java.util.logging.Logger.log(Level.SEVERE String)` with `Logger.severe(String)`.
29org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelWarningSupplierToMethodRecipeReplace JUL `Logger.log(Level.WARNING Supplier<String>)` with `Logger.warning(Supplier<String>)`Replace calls to `java.util.logging.Logger.log(Level.WARNING Supplier<String>)` with `Logger.warning(Supplier<String>)`.
30org.openrewrite.java.logging.jul.LoggerLevelArgumentToMethodRecipes$LogLevelWarningToMethodRecipeReplace JUL `Logger.log(Level.WARNING String)` with `Logger.warning(String)`Replace calls to `java.util.logging.Logger.log(Level.WARNING String)` with `Logger.warning(String)`.
31org.openrewrite.java.logging.log4j.ConvertJulEnteringRewrites JUL's Logger#entering method to Log4j APIReplaces JUL's Logger#entering method calls to Log4j API Logger#traceEntry calls.
32org.openrewrite.java.logging.log4j.ConvertJulExitingRewrites JUL's Logger#exiting method to Log4j APIReplaces JUL's Logger#exiting method calls to Log4j API Logger#traceEntry calls.
33org.openrewrite.java.logging.log4j.LoggerSetLevelToConfiguratorRecipeConvert Log4j `Logger.setLevel` to Log4j2 `Configurator.setLevel`Converts `org.apache.log4j.Logger.setLevel` to `org.apache.logging.log4j.core.config.Configurator.setLevel`.
34org.openrewrite.java.logging.logback.ConfigureLoggerLevelConfigure logback logger levelWithin logback.xml configuration files sets the specified log level for a particular class. Will not create a logback.xml if one does not already exist.
35org.openrewrite.java.logging.logback.Log4jAppenderToLogbackMigrate Log4j 2.x Appender to logback-classic equivalentsMigrates custom Log4j 2.x Appender components to `logback-classic`. This recipe operates on the following assumptions: 1.) The contents of the `append()` method remains unchanged. 2.) The `requiresLayout()` method is not used in logback and can be removed. 3.) In logback the `stop()` method is the equivalent of log4j's close() method. For more details see this page from logback: [`Migration from log4j`](http://logback.qos.ch/manual/migrationFromLog4j.html).
36org.openrewrite.java.logging.logback.Log4jLayoutToLogbackMigrate Log4j 2.x Layout to logback-classic equivalentsMigrates custom Log4j 2.x Layout components to `logback-classic`. This recipe operates on the following assumptions: 1. A logback-classic layout must extend the `LayoutBase<ILoggingEvent>` class. 2. log4j's `format()` is renamed to `doLayout()` in a logback-classic layout. 3. LoggingEvent `getRenderedMessage()` is converted to LoggingEvent `getMessage()`. 4. The log4j ignoresThrowable() method is not needed and has no equivalent in logback-classic. 5. The activateOptions() method merits further discussion. In log4j a layout will have its activateOptions() method invoked by log4j configurators that is PropertyConfigurator or DOMConfigurator just after all the options of the layout have been set. Thus the layout will have an opportunity to check that its options are coherent and if so proceed to fully initialize itself. 6. In logback-classic layouts must implement the LifeCycle interface which includes a method called start(). The start() method is the equivalent of log4j's activateOptions() method. For more details see this page from logback: [`Migration from log4j`](http://logback.qos.ch/manual/migrationFromLog4j.html).
37org.openrewrite.java.logging.slf4j.ChangeLogLevelChange SLF4J log levelChange the log level of SLF4J log statements.
38org.openrewrite.java.logging.slf4j.JulGetLoggerToLoggerFactoryRecipesReplace JUL Logger creation with SLF4J LoggerFactoryReplace calls to `Logger.getLogger` with `LoggerFactory.getLogger`.
39org.openrewrite.java.logging.slf4j.JulGetLoggerToLoggerFactoryRecipes$GetLoggerClassCanonicalNameToLoggerFactoryRecipeReplace JUL `Logger.getLogger(Some.class.getCanonicalName())` with SLF4J's `LoggerFactory.getLogger(Some.class)`Replace calls to `java.util.logging.Logger.getLogger(Some.class.getCanonicalName())` with `org.slf4j.LoggerFactory.getLogger(Some.class)`.
40org.openrewrite.java.logging.slf4j.JulGetLoggerToLoggerFactoryRecipes$GetLoggerClassNameToLoggerFactoryRecipeReplace JUL `Logger.getLogger(Some.class.getName())` with SLF4J's `LoggerFactory.getLogger(Some.class)`Replace calls to `java.util.logging.Logger.getLogger(Some.class.getName())` with `org.slf4j.LoggerFactory.getLogger(Some.class)`.
41org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipesReplace JUL active Level check with corresponding SLF4J method callsReplace calls to `Logger.isLoggable(Level)` with the corresponding SLF4J method calls.
42org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelAllRecipeReplace JUL `Logger.isLoggable(Level.ALL)` with SLF4J's `Logger.isTraceEnabled`Replace calls to `java.util.logging.Logger.isLoggable(Level.ALL)` with `org.slf4j.Logger.isTraceEnabled()`.
43org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelConfigRecipeReplace JUL `Logger.isLoggable(Level.CONFIG)` with SLF4J's `Logger.isInfoEnabled()`Replace calls to `java.util.logging.Logger.isLoggable(Level.CONFIG)` with `org.slf4j.Logger.isInfoEnabled()`.
44org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelFineRecipeReplace JUL `Logger.isLoggable(Level.FINE)` with SLF4J's `Logger.isDebugEnabled()`Replace calls to `java.util.logging.Logger.isLoggable(Level.FINE)` with `org.slf4j.Logger.isDebugEnabled()`.
45org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelFinerRecipeReplace JUL `Logger.isLoggable(Level.FINER)` with SLF4J's `Logger.isTraceEnabled()`Replace calls to `java.util.logging.Logger.isLoggable(Level.FINER)` with `org.slf4j.Logger.isTraceEnabled()`.
46org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelFinestRecipeReplace JUL `Logger.isLoggable(Level.FINEST)` with SLF4J's `Logger.isTraceEnabled`Replace calls to `java.util.logging.Logger.isLoggable(Level.FINEST)` with `org.slf4j.Logger.isTraceEnabled()`.
47org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelInfoRecipeReplace JUL `Logger.isLoggable(Level.INFO)` with SLF4J's `Logger.isInfoEnabled()`Replace calls to `java.util.logging.Logger.isLoggable(Level.INFO)` with `org.slf4j.Logger.isInfoEnabled()`.
48org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelSevereRecipeReplace JUL `Logger.isLoggable(Level.SEVERE)` with SLF4J's `Logger.isErrorEnabled()`Replace calls to `java.util.logging.Logger.isLoggable(Level.SEVERE)` with `org.slf4j.Logger.isErrorEnabled()`.
49org.openrewrite.java.logging.slf4j.JulIsLoggableToIsEnabledRecipes$LoggerIsLoggableLevelWarningRecipeReplace JUL `Logger.isLoggable(Level.WARNING)` with SLF4J's `Logger.isWarnEnabled()`Replace calls to `java.util.logging.Logger.isLoggable(Level.WARNING)` with `org.slf4j.Logger.isWarnEnabled()`.
50org.openrewrite.java.logging.slf4j.JulLevelAllToTraceRecipeReplace JUL `Level.ALL` logging with SLF4J's trace levelReplace `java.util.logging.Logger#log(Level.ALL String)` with `org.slf4j.Logger#trace(String)`.
51org.openrewrite.java.logging.slf4j.JulParameterizedArgumentsReplace parameterized JUL level call with corresponding SLF4J method callsReplace calls to parameterized `Logger.log(LevelString…)` call with the corresponding slf4j method calls transforming the formatter and parameter lists.