Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParameterizedLogging should also replace String.format / .formatted #149

Open
koppor opened this issue May 27, 2024 · 1 comment
Open

ParameterizedLogging should also replace String.format / .formatted #149

koppor opened this issue May 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@koppor
Copy link

koppor commented May 27, 2024

Got:

-            LOGGER.debug(String.format("Could not parse the FileAnnotation %s into any known FileAnnotationType. It was %s!", annotation, annotation.getSubtype()));
+            LOGGER.debug("Could not parse the FileAnnotation %s into any known FileAnnotationType. It was %s!".formatted(annotation, annotation.getSubtype()))

Expected:

LOGGER.debug("Could not parse the FileAnnotation {} into any known FileAnnotationType. It was {}.", annotation, annotation.getSubtype());

Similarly,

-  LOGGER.warn("Unexpected attribute '%s' for <%s>".formatted(key, tagName));
+  LOGGER.warn("Unexpected attribute '{}' for <{}>", key, tagName);

I checked https://github.com/openrewrite/rewrite-logging-frameworks/blob/main/src/test/java/org/openrewrite/java/logging/ParameterizedLoggingTest.java - and there is no test for String.format and .formatted.

@timtebeek
Copy link
Contributor

Indeed seems like a decent extension of the existing recipe. There's some limitations of course when we can apply such a code change, but good suggestion for the limited cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants