I'm developing an Apache module. Throughout development I discovered it simple to use logging functions at various points during my code. For instance after opening personal files, I'd log a mistake when the operation wasn't effective to ensure that I might know precisely in which the problem happened during my code.

Now, I'm going to deliver my module to my boss (I'm with an internship). I needed to do you know the guidelines regarding logging. Could it be great for maintenance reasons or perhaps is it bad since it may hamper the response duration of the server.

It truly is dependent how you authored individuals logging instructions. Should you authored:

logger.debug(computeSomeCostlyDebugOutput());

You may affect performance badly when the logger isn't set on the DEBUG level (computeSomeCostlyDebugOutput will invariably make time to execute and it is result will be overlooked through the logger otherwise matching the DEBUG level).

Should you write it such as this rather:

if (logger.isDebugEnabled()) {
  logger.debug(computeSomeCostlyDebugOutput());
}

then your pricey procedures and logging will occur only when the right logger level is placed (i.e. the logger will not neglected). It essentially functions like another switch for that logger, the very first switch being the set up logger level.

As Andrzej Doyle perfectly stated, the logger will check its level internally, but this occurs within the debug method, after time had been wasted within the computeSomeCostlyDebugOutput. Should you spend your time in computeSomeCostlyDebugOutput, you best get it done when you are aware that it is result will not maintain vain.

Lots of software ships with logging instructions which you'll activate if you want more particulars into intricacies of the one thing, execution path and stuff. Just make certain they may be deactivated and just take computing time when the appropriate level is placed.

Among the design goals of Log4J (permanently reason) was performance Ceki Gulku wanted the library to become functional being produced, enterprise software and also the overhead of Log4J is really pretty minimal (measured by myself webapp project having a profiler).

A couple of things which are prone to take a while though, are:

  1. Developing the arguments to pass in to the logging method, for many calls. As dpb states, this ought to be prevented by wrapping any computation of complex output inside a logging check so you are not drawing complex debug output once the logger's likely to dispose of it as it is set to simply record errors.
  2. The sheer I/O needed to record the log data. If you have the application logging 200Mb of debug logs per second (it could seem infeasible, but it is happened in my experience before) then that's prone to put stress how fast it runs, as IIRC the file writing happens synchronously. In a variety of webapp-type projects I have developed, I'm able to usually really watch a slight difference in responsiveness after i set the logs to debug level (and IMO this can be a positive thing, while you should be producing lots of output whenever you request for debug logs).