Alex Rivera | Logout

Enclosing calls to debug() in if isDebugEnabled(): a good policy?

Asked 2009-03-17T09:07:12.340
30

Our team has the policy of doing logging like

if (LOGGER.isDebugEnabled()) {  
  LOGGER.debug("model[" + model + "]");
}

instead of simply calling the logging method like this:

LOGGER.debug("model[" + model + "]");

This practice is capable of leading to some performance improvement, but on the other hand it makes the codebase more complex. Our application has no performance problems, probably never will, the argument for the introduction of the policy was simply that it's a good practice, so it shall be used every time we are doing logging.

Do you think it's a good policy?

Edit
Report

1 Answer

9

I agree with the famous quote of Michael A. Jackson:

The First Rule of Program Optimization: Don't do it.

The Second Rule of Program Optimization – For experts only: Don't do it yet.

I think that in the majority of cases it's not worth making the codebase more complex without being sure that the performance gain will be noticable / significant.

I'm aware of the performance improvement, but I think it shall be the responsibility of the individual programmer to decide whether it's worth to add those extra lines of code in a particular case. In most cases the extra lines are just adding complexity without any noticable gain on the performance side.

answered 2009-03-17T09:12:05.883

Your Answer