Simple wrapper API around multiple logging APIs.
This package provides an API for logging in server-based applications that can be used around a variety of different logging implementations, including prebuilt support for the following:
java.util.logging.Logger
instance.Logger
.Log
ImplementationThe Logging Package APIs are configured based on the values of system properties, which are normally set on the command line that started your application. The following system properties are global to all Log implementations:
org.apache.commons.logging.log
- Fully qualified class name
of the org.apache.commons.logging.Log
implementation to be
used.If you do not specify the class name of the Log implementation to use, the following algorithm is applied:
java.util.logging.Logger
for the specified name.The basic principle is that the user is totally responsible for the configuration of the underlying logging system. Commons-logging should not change the existing configuration.
Each individual Log implementation may support its own configuration properties. These will be documented in the class descriptions for the corresponding implementation class.
Finally, some Log
implementations (such as the one for Log4J)
require an external configuration file for the entire logging environment.
This file should be prepared in a manner that is specific to the actual logging
technology being used.
Use of the Logging Package APIs, from the perspective of an application component, consists of the following steps:
debug()
, info()
,
warn()
, error
, and fatal()
).For example, you might use the following technique to initialize and use a Log instance in an application component:
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogSource; public class MyComponent { protected Log log = LogSource.getInstance("my.component"); // Called once at startup time public void start() { ... log.info("MyComponent started"); ... } // Called once at shutdown time public void stop() { ... log.info("MyComponent stopped"); ... } // Called repeatedly to process a particular argument value // which you want logged if debugging is enabled public void process(String value) { ... // Do the string concatenation only if logging is enabled if (log.isDebugEnabled()) log.debug("MyComponent processing " + value); ... } }