You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Tomcat logs its output in a file called catalina.out. Such file contains the output from the server itself and from all the web applications that don't specify an alternative output file.

Different loggers can be used to log web application outputs. The following instructions are for Log4j.

Web Application logging with Log4j

To include log4j logging in your web application add the following dependency to your maven project file:

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

Create a file called log4j.properties in WEB-INF/classes with the following content, where you have replaced APPLICATION_OUTPUT_FILE with your choice of output file name (it would be nice to have in it the name of the application that produced the file):

#
# Configures Log4j as the Tomcat system logger
#

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

#
# Configuration for a rolling log file
#
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

If you now redeploy your application all the output from your application should be logged in the file you chose.

Monitoring the log file

Use probe to monitor the log file produced by your application going to:

http://_serverName_.slac.stanford.edu:8080/probe/logs/

where serverName is the tomcat server on which the application has been deployed.

  • No labels