Log4j Installation

In order to use the tools we are about to install it is necessary to setup the operating environment so that the tools know where to find stuff they need and the operating system knows where to find the tools. A understanding of how to do this is essential as you will be asked to change the operating environment. I have comprehensively covered this in documents entitled Configuring A Windows Working Environment and Configuring A Unix Working Environment.

1. Download the log4j distribution from http://jakarta.apache.org/log4j/docs/download.html.

2. Extract the archived files to some suitable directory.

3. Add the file dist/lib/log4j-1.2.6.jar to your CLASSPATH environment variable.

4. Download http://apache.rmplc.co.uk/dist/xml/xerces-j/Xerces-J-bin.2.6.0.zip and unzip it to a temporary directory. Copy the files xercesImpl.jar and xmlParserAPIs.jar to some permanent location and append their paths to the CLASSPATH environment variable.

Log4j vs. JSR47

Required JDK
1.1 or above
1.4 or above
actual users
closed committee
Apache Public License
Sun Community Source License
configuration order
order independent
order independent (as of spec. version 0.75)
Support for API extensions
Appender inheritance
cumulative (as of spec. version 0.75)
Support for object rendering
Configuration file formats
XML and key=value formats
key=value format only with very limited syntax
Support for ErrorHandlers
yes (as of version 0.75)
Filter logic
à la Linux ipchains
Part of JDK

Pros & Cons of Log4j

• log4j is optimized for speed. The burden of logging is minimized.
• log4j is based on a named logger hierarchy.
• log4j is thread-safe.
• The format of the logged message can be specified similar to C language’s printf()
function. For e.g. Formatting can be specified as “%r [%t] %-5p %c{2} %x - %m\n”
• log4j is not restricted to a predefined set of facilities.
• Logging behavior can be set at runtime using a configuration file. Configuration files can
be property files or in XML format.
• log4j is designed to handle Java Exceptions from the start.
• log4j can direct its output to a file, the console, a java.io.OutputStream, java.io.Writer, a
remote server using TCP, a remote Unix Syslog daemon, to a remote listener using JMS,
to the NT EventLog or even send e-mail.
• The format of the log output can be easily changed by extending the Layout class. The
target of the log output as well as the writing strategy can be altered by implementations
of the Appender interface.
• log4j supports multiple output appenders per logger.
• It supports hierarchical logging. It is possible to select (at runtime) which log statements
are output at arbitrary granularity. Users can choose to implement their own log formats
and output strategies.

• Internationalization (Though specified in features, it is not mentioned anywhere else in
the documentation) is not provided
• Asynchronous logging facility is not provided
• Threads are used in Handler objects. As threads should be managed only by the EJB
container and should not be created in the code written by a developer, we have to find a
workaround for this issue. The solutions like writing Java Messaging Service handler or
calling the initialization code of the framework from start-up classes of application server
need more investigation.