Links

Use logger instead of system print statements

org.openrewrite.java.logging.SystemOutToLogging Replace System.out print statements with a logger.

Source

  • groupId: org.openrewrite.recipe
  • artifactId: rewrite-logging-frameworks
  • version: 1.15.0

Options

Type
Name
Description
Boolean
addLogger
Optional. Add a logger field to the class if it isn't already present.
String
loggerName
Optional. The name of the logger to use when generating a field.
String
loggingFramework
Optional. The logging framework to use.
String
level
Optional. The logging level to turn System.out print statements into.

Usage

This recipe has no required configuration options and can be activated directly after taking a dependency on org.openrewrite.recipe:rewrite-logging-frameworks:1.15.0 in your build file:
Gradle
Maven POM
Maven Command Line
build.gradle
plugins {
id("org.openrewrite.rewrite") version("5.32.0")
}
rewrite {
activeRecipe("org.openrewrite.java.logging.SystemOutToLogging")
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-logging-frameworks:1.15.0")
}
pom.xml
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.37.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.logging.SystemOutToLogging</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-logging-frameworks</artifactId>
<version>1.15.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
shell
mvn org.openrewrite.maven:rewrite-maven-plugin:4.37.0:run \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-logging-frameworks:1.15.0 \
-DactiveRecipes=org.openrewrite.java.logging.SystemOutToLogging
Recipes can also be activated directly from the command line by adding the argument -Drewrite.activeRecipes=org.openrewrite.java.logging.SystemOutToLogging