ParameterizedLogging recipe doesn't support Log4j2 lambda method
Originally reported in https://github.com/openrewrite/rewrite-logging-frameworks/issues/159 but haven't fully fixed. This report will include the leftover only.
What version of OpenRewrite are you using?
I am using
- OpenRewrite v5.35.0
- Maven/Gradle plugin v3.9.8
- rewrite-logging-frameworks v2.10.0
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.35.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.logging.log4j.ParameterizedLogging</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-logging-frameworks</artifactId>
<version>2.10.0</version>
</dependency>
</dependencies>
</plugin>
What is the smallest, simplest way to reproduce the problem?
@Log4j2
class A {
public static final Marker MY_MARKER = MarkerManager.getMarker("my-A");
void foo(String bar) {
log.debug(MY_MARKER, () -> bar);
}
}
What did you expect to see?
@Log4j2
class A {
public static final Marker MY_MARKER = MarkerManager.getMarker("my-A");
void foo(String bar) {
log.debug(MY_MARKER, () -> bar);
}
}
What did you see instead?
@Log4j2
class A {
public static final Marker MY_MARKER = MarkerManager.getMarker("my-A");
void foo(String bar) {
log.debug("{}", MY_MARKER, () -> bar);
}
}
What is the full stack trace of any errors you encountered?
stacktrace output here
Are you interested in contributing a fix to OpenRewrite?
Thanks for reporting your new findings @jeffreye ! Seems indeed like that case isn't covered yet; would you want to help out with a unit test on a draft PR, similar as we saw on https://github.com/openrewrite/rewrite-logging-frameworks/pull/162/files?diff=unified&w=1 ?
From there it's likely a small step to see this case covered as well.
Not reproducible with the following test
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
@Log4j2
class A {
public static final Marker MY_MARKER = MarkerManager.getMarker("my-A");
void foo(String bar) {
log.debug(MY_MARKER, () -> bar);
}
}
Try to analyse other cases.
So this has likely been improved by our addition of Lombok support.
Found the case:
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import java.util.function.Supplier;
@Log4j2
class A {
public static final Marker MY_MARKER = MarkerManager.getMarker("my-A");
void foo(String bar) {
Supplier supplier = () -> bar;
log.debug(MY_MARKER, supplier);
}
}
Got:
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import java.util.function.Supplier;
@Log4j2
class A {
public static final Marker MY_MARKER = MarkerManager.getMarker("my-A");
void foo(String bar) {
Supplier supplier = () -> bar;
log.debug("{}", MY_MARKER, supplier)
}
}