Although in some tutorials, for example here (Parametrized logging section), said that Logback message {}
parametrization help us to avoid unnecess
When you make a method call, e.g. employeeService.calculateBonus(employee)
, you're calling that method. Simple as that. So you are calculating the employee bonus every time this line is hit. There is no lazy evaluation here.
Whether or not to use log.isDebugEnabled()
depends on the situation. In this situation, if that method call is expensive, you should wrap that in a debug enabled check.
In the case of getters, this isn't usually necessary. So, for instance, I would not wrap this in an isDebugEnabled
check:
log.debug("Calculating bonus for employee {} {}", employee.firstName(), employee.lastName());
These are simple getters that return a String
, so no expensive calculations are done.