Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
<dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.1</version>
   <type>jar</type>
   <url>http://jakarta.apache.org/commons/logging</url>
   <properties>
      <war.bundle>true</war.bundle>
   </properties>
</dependency>
<dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.13</version>
   <type>jar</type>
   <url>http://logging.apache.org/log4j/docs/</url>
   <properties>
      <war.bundle>true</war.bundle>
   </properties>
</dependency>

Logging is configured via a properties file (called log4j.properties) that you have to create in WEB-INF/classes. With the following properties file the output is logged in a file called

Code Block

${APPLICATION_OUTPUT_FILE}.log

The output file is backed up once it reaches 0.5 Mb in size and a maximum of 4 backups are kept.

Code Block

#
# Configure the logger to output info level messages into a rolling log file.
#
log4j.rootLogger=INFO, R

#
# Default output file name
#
application.context=tomcat

#
# Configuration for a rolling log file ("tomcat.log").
#
log4j.appender.R=org.apache.log4j.RollingFileAppender
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
log4j.appender.R.File=${catalina.base}/logs/APPLICATION_OUTPUT_FILE.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxFileSize=5036KB
log4j.appender.R.MaxBackupIndex=4

#
# Print the date in ISO 8601 format
#
log4j.appender.R.layout.ConversionPattern=%d %-5p - %m%n

For more configuration options please refer to the log4j documentation at http://logging.apache.org/log4j/docs/.

Logj4 offers more flexibility than java.util.logging but requires additional dependencies.

Redirection stdout and stderr to Logger

...