previous next TOC
Logging Performance

  1. Performance when logging is turned off is extremely fast (~25 nanoseconds) but incurs the hidden cost of parameter construction.

    For example, for some logger cat, writing,

    logger.debug("Entry: "+i+"="+entry[i]);
    incurs the cost of constructing the message parameter, i.e. converting both integer i and entry[i] to a String, and concatenating intermediate strings, regardless of whether the message will be logged or not.

    To avoid the parameter construction cost write:

    if(logger.isDebugEnabled() {
      logger.debug("Entry: "+i+"="+(entry[i]));
    }
  2. Performance of logging when logging is turned on is determined by the cost of walking the logger hierarchy. Typical cost of a hierarchy walk is in the range 5 to 15 microseconds.

  3. Actual logging is in order of 100 to 300 micro-seconds.


All measurements were done on a 233 MHz Pentium II machine. See org.apache.log4j.performance.NotLogging  and org.apache.log4j.performance.Logging  for actual figures for your environment.

Although log4j has many features, one of it foremost design goals was speed.

 

GET THE DOCS DIRECTLY FROM THE DEVELOPER
For up to date and detailed log4j documentation directly from the developer please consider The complete log4j manual.