Use lambda suppliers for Log4j parameters and composed messages

MSAL

Replace parameterized Log4j 2 log statements such as logger.debug(String message, Object... params) with logger.debug(String message, Supplier<?>... paramSuppliers), so that the parameters are only evaluated when the log level is enabled. A message without parameters that is put together at the call, such as logger.debug("Hello " + name), is passed as a supplier too. Statements whose arguments are all cheap to evaluate, such as variables and simple getters, whose last argument is a Throwable, whose arguments capture local variables that are not effectively final, have side effects, throw checked exceptions or are suppliers themselves are left unchanged.

org.openrewrite.java.logging.log4j.ParameterizedLoggingToLambdaSuppliers

Optional

The log levels whose statements are converted, e.g. trace, debug. Applies to the level methods such as debug(..) as well as to log(Level.DEBUG, ..). Defaults to all levels. A log(..) call whose level is not a Level constant is only converted when no levels are given. Separate values with commas.

mod run . --recipe=org.openrewrite.java.logging.log4j.ParameterizedLoggingToLambdaSuppliers

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.