openrewrite / rewrite-logging-frameworks

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

Logback to log4j2 support #97

Open Misha123456 opened 1 year ago

Misha123456 commented 1 year ago

I was reading the documentation here and can see log4j2 to logback conversion is supported. But there is no way to convert vice versa (from logback to log4j2).

Are there plans to implement this in the future?

timtebeek commented 1 year ago

hi @Misha123456 ! We had not planned to support a migration from logback to log4j2, but are open to contributions in case you're interested to pick that up. Implementation wise I imagine it will be very similar to the log4j2 -> logback recipes. If you're merely looking to switch dependencies you could have a look at META-INF/rewrite/logback.yml, but a full migration might also involve converting for instance logback.xml.

ppkarwasz commented 11 months ago

@timtebeek,

Could you assign this issue to me?

I would split it into two independent recipes:

timtebeek commented 11 months ago

Sure sounds good; Thanks for taking this on!

timtebeek commented 4 months ago

We recently completed quite a few recipes to move from JUL to SLF4J; those are now under: https://github.com/openrewrite/rewrite-logging-frameworks/tree/main/src/main/java/org/openrewrite/java/logging/slf4j

I suspect that the approach taken there could be largely followed here: Mostly use declarative or Refaster recipes, and complement those with explicit recipes as needed, which wouldn't need much.

ppkarwasz commented 4 months ago

We have recently revamped our documentation with:

Unlike the migration from JUL to SLF4J, which requires mostly code changes, migrating from Logback to Log4j Core requires:

  1. A migration of runtime dependencies, which can be easily done with the current declarative Maven/Gradle recipes.
  2. A migration of the configuration file.

The latter requires most of the work, since the configuration options of every standard Logback plugin must be matched to the corresponding options of a Log4j Core plugin. Starting October 2024, I plan to add support for a Logback-to-Log4j Core configuration conversion to the log4j-config-converter artifact introduced in https://github.com/apache/logging-log4j-transform/pull/93. This artifact can then be added as a dependency of the OpenRewrite recipe.

timtebeek commented 4 months ago

Nice to see, thanks! Spotted this note in the docs that ought to be an easy recipe for your users too.

Note that LogManager.getLogger(Foo.class) can be simplified as LogManager.getLogger(), if Foo is the enclosing class of the field.