Search Apache POI

Apache POI - Logging Framework


POI uses a custom logging framework which allows to configure where logs are sent to.

Logging in POI is used only as a debugging mechanism, not a normal runtime logging system. Logging on level debug/info is ONLY for autopsie type debugging, and should NEVER be enabled on a production system.

The framework is extensible so that you can send log messages to any logging framework that your application uses.

A number of default logging implementations are supported by POI out-of-the-box and can be selected via a system property.

Enable logging#

By default, logging is disabled in POI. Sometimes it might be useful to enable logging to see some debug messages printed out which can help in analyzing problems.

You can select the logging framework by setting the system property org.apache.poi.util.POILogger during application startup or by calling System.setProperty():

            System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.CommonsLogger" );

Note: You need to call setProperty() before any POI functionality is invoked as the logger is only initialized during startup.

Available logger implementations#

The following logger implementations are provided by POI:

Class Type
org.apache.poi.util.SystemOutLogger Sends log output to the system console
org.apache.poi.util.NullLogger Default logger, does not log anything
org.apache.poi.util.CommonsLogger Allows to use Apache Commons Logging for logging. This can use JDK1.4 logging, log4j, logkit, ...
org.apache.poi.util.DummyPOILogger Simple logger which will keep all log-lines in memory for later analysis. Used primarily for testing. Note: this may cause a memory leak if used in production application!

Sending logs to a different log framework#

You can send logs to other logging frameworks by implementing the interface org.apache.poi.util.POILogger.

Implementation details#

Every class uses a POILogger to log, and gets it using a static method of the POILogFactory .

Each class in POI can log using a POILogger, which is an abstract class. We decided to make our own logging facade because:

  1. we need to log many values and we put many methods in this class to facilitate the programmer, without having him write string concatenations;
  2. we need to be able to use POI without any logger package present.
by Dominik Stadler