TomcatExpert

How to redirect stderr and stdout messages

posted by SpringSource on December 28, 2009 06:05 PM

How to configure your web application's stderr and stdout messages be redirected to the application's log file for Tomcat 5.5 in ERS 3.x

For standard web applications, error messages and output are streamed to log files using sterr and stdout respectively. Some application developers prefer to aggregate all these messages into the application log.

The following steps are required to configure your web application's stderr and stdout messages be redirected to the application's log file for Tomcat 5.5 in ERS 3.1 utilizing java.util.logging:

 

1. Add the following attribute to the application context in <ERS3.1_install_dir>/servers/<server_instance>/conf/context.xml file:

swallowOutput="true" 

2. Create <ERS3.1_install_dir>/servers/<server_instance>/webapps//WEB-INF/classes/logging.properties with the following content:

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler 
############################################################ 
# Handler specific properties. 
# Describes specific configuration info for Handlers. 
############################################################
org.apache.juli.FileHandler.level = FINE 
org.apache.juli.FileHandler.directory = /servers//logs 
org.apache.juli.FileHandler.prefix = jsp-examples. 
 
java.util.logging.ConsoleHandler.level = FINE 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 

NOTE: In the above example, the application log file with prefix jsp-examples. will be created in the server instance's logs directory.

 

3. To test the configuration, create a JSP page with the following content:

<% 
System.out.println("Test stdout"); 
System.err.println("Test stderr"); 
%> 

The stderr and stdout would continue to be logged in jvm.stdout, they are also logged in the application's log file.

 

 

For more than 10 years, SpringSource employees have been supporting Apache technologies, with unparalleled experience and commitment to the Apache Software Foundation. More than 400 of the Fortune 500 count on SpringSource to support their mission-critical business applications. Leaders of the Apache Software Foundation, including Board Members, work at SpringSource and dedicate a significant amount of time further developing the Apache Tomcat open source project. Over the last 2 years, 95% of the issues fixed in the Apache Tomcat project were fixed by SpringSource engineers. For more information on how SpringSource can help your enterprise, see the SpringSource website, or call 800/444-1935.

Comments

rfc

Can you please clarify if this /servers/ refers to a tomcat directory?
thanks

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.