openrewrite / rewrite-logging-frameworks

OpenRewrite recipes for assisting with Java logging migration tasks.
Apache License 2.0
25 stars 21 forks source link

ParameterizedLogging recipe doesn't support Log4j2 lambda method #167

Open jeffreye opened 4 months ago

jeffreye commented 4 months ago

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

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?

timtebeek commented 4 months ago

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.