diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index 2ea3891d..c77b8dd5 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -62,6 +62,29 @@ public abstract class AbstractRewriteBaseRunMojo extends AbstractRewriteMojo { @Nullable protected LinkedHashSet options; + /** + * The level used to log changes performed by recipes. + */ + @Parameter(property = "rewrite.recipeChangeLogLevel", defaultValue = "WARN") + protected LogLevel recipeChangeLogLevel; + + protected void log(LogLevel logLevel, CharSequence content) { + switch (logLevel) { + case DEBUG: + getLog().debug(content); + break; + case INFO: + getLog().info(content); + break; + case WARN: + getLog().warn(content); + break; + case ERROR: + getLog().error(content); + break; + } + } + /** * Attempt to determine the root of the git repository for the given project. * Many Gradle builds co-locate the build root with the git repository root, but that is not required. @@ -438,7 +461,7 @@ private void logRecipe(RecipeDescriptor rd, String prefix) { recipeString.append(": {").append(opts).append("}"); } } - getLog().warn(recipeString.toString()); + log(recipeChangeLogLevel, recipeString.toString()); for (RecipeDescriptor rchild : rd.getRecipeList()) { logRecipe(rchild, prefix + " "); } diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java index 8cbbadb2..e40ae79d 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteRunMojo.java @@ -71,40 +71,40 @@ public void execute() throws MojoExecutionException { Duration estimateTimeSaved = Duration.ZERO; for (Result result : results.generated) { assert result.getAfter() != null; - getLog().warn("Generated new file " + - result.getAfter().getSourcePath().normalize() + - " by:"); + log(recipeChangeLogLevel, "Generated new file " + + result.getAfter().getSourcePath().normalize() + + " by:"); logRecipesThatMadeChanges(result); estimateTimeSaved = estimateTimeSavedSum(result, estimateTimeSaved); } for (Result result : results.deleted) { assert result.getBefore() != null; - getLog().warn("Deleted file " + - result.getBefore().getSourcePath().normalize() + - " by:"); + log(recipeChangeLogLevel, "Deleted file " + + result.getBefore().getSourcePath().normalize() + + " by:"); logRecipesThatMadeChanges(result); estimateTimeSaved = estimateTimeSavedSum(result, estimateTimeSaved); } for (Result result : results.moved) { assert result.getAfter() != null; assert result.getBefore() != null; - getLog().warn("File has been moved from " + - result.getBefore().getSourcePath().normalize() + " to " + - result.getAfter().getSourcePath().normalize() + " by:"); + log(recipeChangeLogLevel, "File has been moved from " + + result.getBefore().getSourcePath().normalize() + " to " + + result.getAfter().getSourcePath().normalize() + " by:"); logRecipesThatMadeChanges(result); estimateTimeSaved = estimateTimeSavedSum(result, estimateTimeSaved); } for (Result result : results.refactoredInPlace) { assert result.getBefore() != null; - getLog().warn("Changes have been made to " + - result.getBefore().getSourcePath().normalize() + - " by:"); + log(recipeChangeLogLevel, "Changes have been made to " + + result.getBefore().getSourcePath().normalize() + + " by:"); logRecipesThatMadeChanges(result); estimateTimeSaved = estimateTimeSavedSum(result, estimateTimeSaved); } - getLog().warn("Please review and commit the results."); - getLog().warn("Estimate time saved: " + formatDuration(estimateTimeSaved)); + log(recipeChangeLogLevel, "Please review and commit the results."); + log(recipeChangeLogLevel, "Estimate time saved: " + formatDuration(estimateTimeSaved)); try { for (Result result : results.generated) { diff --git a/src/main/java/org/openrewrite/maven/LogLevel.java b/src/main/java/org/openrewrite/maven/LogLevel.java new file mode 100644 index 00000000..c8f12420 --- /dev/null +++ b/src/main/java/org/openrewrite/maven/LogLevel.java @@ -0,0 +1,8 @@ +package org.openrewrite.maven; + +public enum LogLevel { + DEBUG, + INFO, + WARN, + ERROR +}