Apache Commons Logging
Apache Commons Logging is a Java-based logging utility and a programming model for logging and for other toolkits. It provides APIs, log implementations, and wrapper implementations over some other tools.
Log level
The following table defines the log levels and messages in Apache Commons Logging, in decreasing order of severity. The left column lists the log level designation in and the right column provides a brief description of each log level.Level | Description |
fatal | Severe errors that cause premature termination. Expect these to be immediately visible on a status console. |
error | Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. |
warn | Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. |
info | Interesting runtime events. Expect these to be immediately visible on a console, so be conservative and keep to a minimum. |
debug | Detailed information on the flow through the system. Expect these to be written to logs only. |
trace | Most detailed information. Expect these to be written to logs only. |
Configuration
Two basic abstractions, Log and LogFactory, are used in Apache Commons Logging.Example
Sample code may look like as follows:package com.cascadetg.ch09;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Jdk14Logger;
public class LogGenerator