Optimize log statements

MSAL

When trace, debug and info log statements use methods for constructing log messages, those methods are called regardless of whether the log level is enabled. This recipe optimizes these statements by either wrapping them in if-statements (SLF4J 1.x) or converting them to fluent API calls (SLF4J 2.0+) to ensure expensive methods are only called when necessary.

org.openrewrite.java.logging.slf4j.WrapExpensiveLogStatementsInConditionals

Optional

The SLF4J 2.0+ fluent API method that takes the message template: SET_MESSAGE passes it to setMessage(..) ahead of the arguments, LOG passes it to log(..) after the arguments. Defaults to LOG.

mod run . --recipe=org.openrewrite.java.logging.slf4j.WrapExpensiveLogStatementsInConditionals

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