From f49d9e15aebc3381bf6690ed177e10d49c1c0806 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 18 Dec 2024 16:56:29 +0100 Subject: [PATCH] Include `ShortenFullyQualifiedTypeReferences` with `Slf4JToLog4j` --- src/main/resources/META-INF/rewrite/log4j.yml | 1 + .../java/logging/log4j/Slf4jToLog4jTest.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/log4j.yml b/src/main/resources/META-INF/rewrite/log4j.yml index a673e0a..23f458c 100644 --- a/src/main/resources/META-INF/rewrite/log4j.yml +++ b/src/main/resources/META-INF/rewrite/log4j.yml @@ -308,3 +308,4 @@ recipeList: newVersion: latest.release - org.openrewrite.java.logging.ChangeLombokLogAnnotation: loggingFramework: Log4j2 + - org.openrewrite.java.ShortenFullyQualifiedTypeReferences diff --git a/src/test/java/org/openrewrite/java/logging/log4j/Slf4jToLog4jTest.java b/src/test/java/org/openrewrite/java/logging/log4j/Slf4jToLog4jTest.java index 6fa1916..472b51b 100644 --- a/src/test/java/org/openrewrite/java/logging/log4j/Slf4jToLog4jTest.java +++ b/src/test/java/org/openrewrite/java/logging/log4j/Slf4jToLog4jTest.java @@ -54,11 +54,11 @@ void loggerUsage() { import org.slf4j.LoggerFactory; import org.slf4j.Marker; import org.slf4j.MarkerFactory; - + class Test { private static final Logger LOGGER = LoggerFactory.getLogger(Test.class); private static final Marker MARKER = MarkerFactory.getMarker("MARKER"); - + public static void main(String[] args) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("logger message"); @@ -72,11 +72,11 @@ public static void main(String[] args) { import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; - + class Test { private static final Logger LOGGER = LogManager.getLogger(Test.class); private static final Marker MARKER = MarkerManager.getMarker("MARKER"); - + public static void main(String[] args) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("logger message"); @@ -96,7 +96,7 @@ void mdcConversion() { java( """ import org.slf4j.MDC; - + class Test { void method() { MDC.put("key", "value"); @@ -111,7 +111,7 @@ void method() { """ import org.apache.logging.log4j.CloseableThreadContext; import org.apache.logging.log4j.ThreadContext; - + class Test { void method() { ThreadContext.put("key", "value"); @@ -136,7 +136,7 @@ void logBuilder() { import org.slf4j.Logger; import org.slf4j.Marker; import org.slf4j.event.Level; - + class Test { void method(Logger logger, Marker marker, Throwable t) { logger.atLevel(Level.INFO) @@ -150,7 +150,7 @@ void method(Logger logger, Marker marker, Throwable t) { import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; - + class Test { void method(Logger logger, Marker marker, Throwable t) { logger.atLevel(Level.INFO) @@ -222,7 +222,7 @@ void changeLombokLogAnnotation() { java( """ import lombok.extern.slf4j.Slf4j; - + @Slf4j class Test { void method() { @@ -232,7 +232,7 @@ void method() { """, """ import lombok.extern.log4j.Log4j2; - + @Log4j2 class Test { void method() {