Hacker News new | ask | show | jobs
by politician 4936 days ago
In the original code, the debug call is guarded by a condition:

  if (log.isDebugEnabled()) { 
    log.debug("{}", expensiveOp(), debugModeOnlyOp()); 
  }
But in the new code, the calls to expensiveOp and debugModeOnlyOp will be called every time this sequence of code is run regardless of the condition:

  log.debug("{}", expensiveOp(), debugModeOnlyOp());
which is equivalent to the old code:

  var x = expensiveOp();
  var y = debugModeOnlyOp();

  if (log.isDebugEnabled()) { 
    log.debug("{} {}", x, y); 
  }
In most languages that do not support macros, it's impossible to correctly state the dependency of expensiveOp & debugModeOnlyOp on the log.isDebugEnabled() flag using log4j's new API.