A log4j Code Example

The following code example demonstrates the process for using logging with the log4j package. This program begins by importing the org.apache.log4j package. This package is not part of the standard JDK and must be downloaded from the Jakarta/Apache site (http://jakarta.apache.org/log4j). Within the package downloaded is a JAR file (for version 1.2, it is named log4j-1.2.jar) that must be made visible to the Java Runtime Environment (JRE) of the application using the package (in the classpath or in the $JAVA_HOME/jre/lib/ext directory).

This code example loads the log4j configuration using a URL (in string format), which is used to set the value of the log4j.configuration System property. This value could also have been set ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.