Log4j
(handling both log4j 1.x
or log4j 2.x
) to the Simple Logging Facade for Java (SLF4J
).mvn rewrite:run
or gradlew rewriteRun
. After running the migration you can inspect the results with git diff
(or equivalent), manually fix anything that wasn't able to be migrated automatically, and commit the results.SLF4J Migrator
, the goal of the Log4jToSlf4j
recipe is to significantly reduce the amount of work involved in migrating Log4j
to SLF4J
. Because OpenRewrite works by leveraging type-attributed Abstract Syntax Trees (AST) representing your source code, the Log4jToSlf4j
recipe can overcome several limitations discussed in the SLF4J Migrator
guide..toString()
Log4j
logging statements are automatically migrated to use the SLF4J Parameterized Logging
equivalent(see "Use SLF4J Parameterized Logging"), messages of type String
are supported. Therefore, there is no need to add a .toString()
method invocation on the object.FATAL
to ERROR
Log4j
log level FATAL
is not supported in SLF4J
. Therefore, FATAL
level log statements are migrated to ERROR
level.type
informationException
MigrationsLog4j
ERROR
log level exceptions are migrated to their SLF4J
equivalent:log4j
properties and configuration files are not migrated.Log4j
configuration customizations which do not have an SLF4J
equivalent cannot be migrated.