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

Add SLF4J 2.x to Log4j API rewrite rule #134

Merged
merged 2 commits into from
Dec 27, 2023

Conversation

ppkarwasz
Copy link
Contributor

@ppkarwasz ppkarwasz commented Dec 26, 2023

This PR adds a rule to convert code written with SLF4J 1.x/2.x to Log4j API.

What's changed?

It covers:

  • basic Logger methods,
  • compatible LogBuilder/LoggingEventBuilder methods,
  • MDC to ThreadContext conversion,
  • Marker conversion,
  • dependency switch from slf4j-api to log4j-api.

Solves part of #97: it does not cover conversion between Logback and Log4j Core, since the choice of a logging implementation is totally independent from the choice of the API.

This is part of apache/logging-log4j2#2080.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

This PR adds a rule to convert code written with SLF4J 1.x/2.x to Log4j
API.

It covers:

 * basic `Logger` methods,
 * compatible `LogBuilder/LoggingEventBuilder` methods,
 * `MDC` to `ThreadContext` conversion,
 * `Marker` conversion,
 * dependency switch from `slf4j-api` to `log4j-api`.

Solves part of openrewrite#97: it **does** not cover conversion between Logback and
Log4j Core, since the choice of a logging implementation is **totally**
independent from the choice of the API.
@timtebeek timtebeek self-requested a review December 26, 2023 19:27
@timtebeek timtebeek added the recipe Recipe Requested label Dec 27, 2023
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see, thanks a lot! Love the helpful hints in between the yaml recipes, and how the tests cover cases per topic.

@timtebeek timtebeek merged commit 07ae6c8 into openrewrite:main Dec 27, 2023
1 check passed
@ppkarwasz ppkarwasz deleted the slf4j-to-log4j branch December 27, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe Requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants