source: nutchez-0.1/tomcat/webapps/docs/logging.html @ 95

Last change on this file since 95 was 66, checked in by waue, 16 years ago

NutchEz - an easy way to nutch

File size: 21.6 KB
Line 
1<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 - Logging in Tomcat</title><meta value="Allistair Crossley" name="author"><meta value="" name="email"><meta value="Yoav Shapira" name="author"><meta value="yoavs@apache.org" name="email"></head><body vlink="#525D76" alink="#525D76" link="#525D76" text="#000000" bgcolor="#ffffff"><table cellspacing="0" width="100%" border="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img border="0" alt="
2      The Apache Tomcat Servlet/JSP Container
3    " align="right" src="./images/tomcat.gif"></a></td><td><font face="arial,helvetica,sanserif"><h1>Apache Tomcat 6.0</h1></font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img border="0" alt="Apache Logo" align="right" src="./images/asf-logo.gif"></a></td></tr></table><table cellspacing="4" width="100%" border="0"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><tr><!--LEFT SIDE NAVIGATION--><td nowrap="true" valign="top" width="20%"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptor-howto.html">16) MBean Descriptor</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</a></li><li><a href="maven-jars.html">27) Mavenized</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td align="left" valign="top" width="80%"><table cellspacing="4" width="100%" border="0"><tr><td valign="top" align="left"><h1>Apache Tomcat 6.0</h1><h2>Logging in Tomcat</h2></td><td nowrap="true" valign="top" align="right"><small><a href="printer/logging.html"><img alt="Printer Friendly Version" border="0" src="./images/printer.gif"><br>print-friendly<br>version
4                    </a></small></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Important note"><strong>Important note</strong></a></font></td></tr><tr><td><blockquote>
5  <p>
6    By default, only java.util.logging is available for the core Tomcat, as Tomcat uses
7    a package renamed logging implementation which is hardcoded for that logger. Usage of
8    alternate loggers is available after building the extra components (see
9    the <a href="extras.html">extras components</a> documentation), which includes
10    a full commons-logging implementation.
11  </p>
12  </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
13  <p>
14    Tomcat 6.0 uses
15    <a href="http://commons.apache.org/logging">Commons Logging</a>
16    throughout its internal code allowing the
17    developer to choose a logging configuration that suits their needs, e.g
18    java.util.logging or
19    <a href="http://logging.apache.org/log4j">Log4J</a>.
20    Commons Logging provides Tomcat the ability to log
21    hierarchially across various log levels without needing to rely on a particular
22    logging implementation.
23  </p>
24  <p>
25    An important consequence for Tomcat 6.0 is that the &lt;Logger&gt; element found in
26    previous versions to create a <code>localhost_log</code> is no longer a valid nested element
27    of &lt;Context&gt;. Instead, the default Tomcat configuration will use java.util.logging.
28    If the developer wishes to collect detailed internal Tomcat logging (i.e what is happening
29    within the Tomcat engine), then they should configure a logging system such as java.util.logging
30    or log4j as detailed next.
31  </p>
32
33  </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="log4j"><strong>log4j</strong></a></font></td></tr><tr><td><blockquote>
34    <p>
35      Tomcat 6.0 has done away with <code>localhost_log</code> which you may be familiar with
36      as the runtime exception/stack trace log. These types of error are usually thrown
37      by uncaught exceptions, but are still valuable to the developer. They can now be
38      found in the <code>stdout</code> log.
39    </p>
40
41    <p>
42      If you need to setup cross-context detailed logging from within Tomcat's code,
43      then you can use a simple log4j configuration. Note that this logging van be very
44      verbose depending on the log level you chose to use.  Note also that a log4j logging
45      configuration is not going to produce stack trace type logging: those stack traces
46      are output to <code>stdout</code> as discussed above.
47    </p>
48
49    <p>
50      Follow the following steps to setup a file named tomcat.log that has internal
51      Tomcat logging output to it:
52    </p>
53
54    <p>
55      <ol>
56        <li>Create a file called log4j.properties with the following content
57            and save it into $CATALINA_HOME/lib.
58          <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>
59            log4j.rootLogger=debug, R
60            log4j.appender.R=org.apache.log4j.RollingFileAppender
61            log4j.appender.R.File=${catalina.home}/logs/tomcat.log
62            log4j.appender.R.MaxFileSize=10MB
63            log4j.appender.R.MaxBackupIndex=10
64            log4j.appender.R.layout=org.apache.log4j.PatternLayout
65            log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
66            log4j.logger.org.apache.catalina=DEBUG, R
67          </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div>
68  </li>
69
70  <li><a href="http://logging.apache.org/log4j">Download Log4J</a> 
71            (v1.2 or later) and place the log4j jar in $CATALINA_HOME/lib.</li>
72
73        <li>Build the commons-logging additional component using the extras.xml
74        Ant build script which is part of teh Tomcat source bundle.</li>
75       
76        <li>Replace <code>$CATALINA_HOME/bin/tomcat-juli.jar</code> with
77        <code>output/extras/tomcat-juli.jar</code>.</li>
78
79        <li>Place <code>output/extras/tomcat-juli-adapters.jar</code> in
80        $CATALINA_HOME/lib.</li>
81
82  <li>Start Tomcat</li>
83      </ol>
84    </p>
85
86    <p>
87      This log4j configuration sets up a file called tomcat.log in your
88      Tomcat logs folder with a maximum file size of 10MB and
89      up to 10 backups.  DEBUG level is specified which will result in the
90      most verbose output from Tomcat.
91    </p>
92 
93    <p>
94      You can (and should) be more picky about which packages to include
95      in the logging. Tomcat 6 uses defines loggers by Engine and Host names.
96      For example, for a default Catalina localhost log, add this to the
97      end of the log4j.properties above. Note that there are known issues with
98      using this naming convention (with square brackets) in log4j XML based
99      configuration files, so we recommend you use a properties file as described
100      until a future version of log4j allows this convention.
101     
102      <ul>
103        <li>log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R</li>
104  <li>log4j.logger.org.apache.catalina.core=DEBUG, R</li>
105  <li>log4j.logger.org.apache.catalina.session=DEBUG, R</li>
106      </ul>
107
108      Be warned a level of DEBUG will produce megabytes of logging and slow startup
109      of Tomcat. This level should be used sparingly when debugging of internal Tomcat
110      operations is required.
111    </p>
112 
113    <p>
114      Your web applications should certainly use their own log4j configuration.
115      This is valid <i>with</i> the above configuration.  You would place a similar log4j.properties
116      file in your web application's WEB-INF/classes folder, and log4j1.2.8.jar into
117      WEB-INF/lib. Then specify your package level logging. This is a basic setup of log4j
118      which does *not* require Commons-Logging,
119      and you should consult the
120      <a href="http://logging.apache.org/log4j/docs/documentation.html">log4j documentation</a> 
121      for more options.  This page is intended only as a bootstrapping guide.
122    </p>
123 
124  </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="java.util.logging"><strong>java.util.logging</strong></a></font></td></tr><tr><td><blockquote>
125
126  <p>
127    The default implemenatation of java.util.logging provided in the JDK is too limited to be
128    useful. A limitation of JDK Logging appears to be the inability to have per-web application logging,
129    as the configuration is per-VM. As a result, Tomcat will, in the default configuration,
130    replace the default LogManager implementation with a container friendly implementation
131    called JULI, which addresses these shortcomings. It supports the same configuration mechanisms
132    as the standard JDK java.util.logging, using either a programmatic approach, or properties
133    files. The main difference is that per-classloader properties files can be set (which enables easy
134    redeployment friendly webapp configuration), and the properties files support slightly extended
135    constructs which allows more freedom for defining handlers and assigning them to loggers.
136  </p>
137  <p>
138    JULI is enabled by default in Tomcat 6.0, and supports per classloader configuration, in addition to
139    the regular global java.util.logging configuration. This means that logging can be configured at
140    the following layers:
141    <ul>
142      <li>In the JDK's logging.properties file. Check
143      your JAVA_HOME environment setting to see which JDK Tomcat is using. The file will be in
144      <code>$JAVA_HOME/jre/lib</code>.
145      Alternately, it can also use a global configuration file located elsewhere by using the
146      system property <code>java.util.logging.config.file</code>, or programmatic configuration using
147      <code>java.util.logging.config.class</code>.</li>
148      <li>In each classloader using a logging.properties file. This means that it is possible to have a
149      configuration for the Tomcat core, as well as separate configurations for each webapps which will
150      have the same lifecycle as the webapps.</li>
151    </ul>
152  </p>
153  <p>
154    The default logging.properties specifies a ConsoleHandler for routing logging to stdout and
155    also a FileHandler. A handler's log level threshold can be set using SEVERE, WARNING, INFO,
156    CONFIG, FINE, FINER, FINEST or ALL. The logging.properties shipped with JDK is set to INFO. You
157    can also target specific packages to collect logging from and specify a level. Here is how
158    you would set debugging from Tomcat. You would need to ensure the ConsoleHandler's level is also
159    set to collect this threshold, so FINEST or ALL should be set. Please refer to Sun's java.util.logging
160    documentation for the complete details.
161  </p>
162  <p>
163    <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>org.apache.catalina.level=FINEST</pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div>
164  </p>
165  <p>
166    The configuration used by JULI is extremely similar, but uses a few extensions to allow better
167    flexibility in assigning loggers. The main differences are:
168    <ul>
169      <li>A prefix may be added to handler names, so that multiple handlers of a single class may be
170      instantiated. A prefix is a String which starts with a digit, and ends with '.'. For example,
171      <code>22foobar.</code> is a valid prefix.</li>
172      <li>As in Java 5.0, loggers can define a list of handlers using the <code>loggerName.handlers</code>
173      property.</li>
174      <li>By default, loggers will not delegate to their parent if they have associated handlers. This
175      may be changed per logger using the <code>loggerName.useParentHandlers</code> property, which accepts
176      a boolean value.</li>
177      <li>The root logger can define its set of handlers using a <code>.handlers</code> property.</li>
178      <li>System property replacement for property values which start with ${systemPropertyName}.</li>
179    </ul>
180  </p>
181  <p>
182    Example logging.properties file to be placed in $CATALINA_BASE/conf:
183    <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>
184handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, \
185           3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, \
186           java.util.logging.ConsoleHandler
187
188.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
189
190############################################################
191# Handler specific properties.
192# Describes specific configuration info for Handlers.
193############################################################
194
1951catalina.org.apache.juli.FileHandler.level = FINE
1961catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1971catalina.org.apache.juli.FileHandler.prefix = catalina.
198
1992localhost.org.apache.juli.FileHandler.level = FINE
2002localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2012localhost.org.apache.juli.FileHandler.prefix = localhost.
202
2033manager.org.apache.juli.FileHandler.level = FINE
2043manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2053manager.org.apache.juli.FileHandler.prefix = manager.
206
2074admin.org.apache.juli.FileHandler.level = FINE
2084admin.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2094admin.org.apache.juli.FileHandler.prefix = admin.
210
211java.util.logging.ConsoleHandler.level = FINE
212java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
213
214
215############################################################
216# Facility specific properties.
217# Provides extra control for each logger.
218############################################################
219
220org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
221org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = \
222   2localhost.org.apache.juli.FileHandler
223
224org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
225org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = \
226   3manager.org.apache.juli.FileHandler
227
228org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/admin].level = INFO
229org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/admin].handlers = \
230   4admin.org.apache.juli.FileHandler
231
232# For example, set the com.xyz.foo logger to only log SEVERE
233# messages:
234#org.apache.catalina.startup.ContextConfig.level = FINE
235#org.apache.catalina.startup.HostConfig.level = FINE
236#org.apache.catalina.session.ManagerBase.level = FINE
237    </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div>
238    </p>
239   
240    <p>
241      Example logging.properties for the servlet-examples web application to be placed
242      in WEB-INF/classes inside the web application:
243      <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>
244handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
245
246############################################################
247# Handler specific properties.
248# Describes specific configuration info for Handlers.
249############################################################
250
251org.apache.juli.FileHandler.level = FINE
252org.apache.juli.FileHandler.directory = ${catalina.base}/logs
253org.apache.juli.FileHandler.prefix = servlet-examples.
254
255java.util.logging.ConsoleHandler.level = FINE
256java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
257      </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div>
258    </p>
259
260  </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font size="-1" color="#525D76"><em>
261        Copyright &copy; 1999-2008, Apache Software Foundation
262        </em></font></div></td></tr></table></body></html>
Note: See TracBrowser for help on using the repository browser.