7.12. Obtaining Apache Log4J
Problem
You need to use Apache Log4J to print statements to a log file for informational or debugging purposes.
Solution
Download Apache Log4J 1.2.8 from the Binary Downloads page
(http://logging.apache.org/site/binindex.cgi)
of the Apache Logging Services project. On this page you will find
two links to Jakarta-log4j-1.2.8.tar.gz and
Jakarta-log4j-1.2.8.zip. Once this archive is
uncompressed, you will find a log4j-1.2.8.jar
file in the dist/lib directory. Put this JAR
file in your classpath and you will be ready to use Log4J in your
application.
Discussion
Log4J (formerly known as Jakarta Log4J) is a highly configurable
logging framework providing hierarchical loggers, various log
destinations, and log formats. Messages are written to Log4J
Logger objects, which represent a specific
category in a hierarchy of log categories; for example, the
com.discursive.Blah category is a child of the
com.discursive category. All messages sent to a
child category are sent to each ancestor in a tree of
Logger categories. A category can be assigned an
Appender and a Layout; an
Appender controls where a message is sent, and a
Layout defines the formatting and contents of a
message. Log4J ships with a number of Appender
implementations, including SMTPAppender,
RollingFileAppender,
SocketAppender, SyslogAppender,
and NTEventLogAppender. Log4J also ships with a
number of Layout implementations, including
XMLLayout, PatternLayout,
HTMLLayout, and DateLayout.
See Also
For more ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access