Reports the logging calls with non-constant arguments that are not surrounded by a guard condition. The evaluation of the arguments of a logging call can be expensive. Surrounding a logging call with a guard clause prevents that cost when logging is disabled for the level used by the logging statement. This is especially useful for the least serious level (trace, debug, finest) of logging calls, because those are most often disabled in a production environment.

Example:


  public class Principal {
    void bad(Object object) {
      if (true) {
        LOG.debug("log log log " + expensiveCalculation(object));
      }
      LOG.debug("some more logging " + expensiveCalculation(1));
    }

    void good(Object) {
      if (LOG.isDebug()) {
        LOG.debug("value: " + expensiveCalculation(object));
      }
    }
  }

Configure the inspection: