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

Compare with Current View Page History

« Previous Version 6 Next »

The Tomcat Logging documentation can be found here.

By default Tomcat logs are handled by java.util.logging. It is possible to modify the Tomcat defaults by providing a file called logging.properties as part as the web application resources.

By default 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.

To separate the output from different web applications in different files (making debugging and troubleshooting a much easier) the Tomcat defaults need to be overwritten.

Logging Properties File

By creating a logging.properties file in your web application, the output from your web application will be sent to a file called APPLICATION_OUTPUT_FILE (by convention we give the output file the name of the application that produced the file):

handlers = org.apache.juli.FileHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = APPLICATION_OUTPUT_FILE.

If you now redeploy your application all the output from your application will be logged in a file called

${APPLICATION_OUTPUT_FILE}-${date}.log

so a file is created each day. There is no way to change this configuration as it is all done internally in tomcat.

It is best to place the logging.properties file in the directory src/resources (see below).

If no such file is provided the output will go to the default catalina.out (or wrapper.out if running with the wrapper).

Logging Output in Netbeans

By default Netbeans will show two output consoles from Tomcat: the server log (in catalina.out) and the server access log (in localhost.out).
When you deploy locally your web application with a logging.properties file like the one above, your output will not show up in the default netbeans console and to debug you will have to find your output file and tail it.

To overcome this problem we have added some resource filtering in the parent web application pom (org-srs-maven-project):

        <profile>
            <id>deploy-local</id>
            <properties>
                <deployment.mode>local</deployment.mode>
            </properties>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <excludes>
                            <exclude>**/logging.properties</exclude>
                        </excludes>
                    </resource>
                </resources>
            </build>
        </profile>

So when the profile deploy-local profile is activated the logging.properties file is excluded from the packaged war file and your output will be logged in the default Tomcat location; and so it should appear in the Netbeans console.

Redirection stdout and stderr to Logger on the Server

By default Tomcat will not redirect stdout and stderr to the Logger. This behaviour can be changed by setting the context parameter swallowOutput to true in context.xml.

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