You need to use Apache Log4J to print statements to a log file for informational or debugging purposes.
To use Apache Log4J 1.2.15 in a Maven 2 project, add the following
dependency to your project's pom.xml
:
Example 7.8. Adding a Dependency on Apache Log4J
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.15</version> <exclusions> <exclusion> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> </exclusion> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> </exclusions> </dependency>
Apache 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
.
For more information about the Apache Logging Services project, see the Logging Services project page at http://logging.apache.org. For more information about the Apache Log4J project, see the Log4J project page at http://logging.apache.org/log4j/docs/.