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

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

NutchEz - an easy way to nutch

File size: 19.2 KB
RevLine 
[66]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><!--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"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></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>
4  <p>
5    By default, only java.util.logging is available for the core Tomcat, as Tomcat uses
6    a package renamed logging implementation which is hardcoded for that logger. Usage of
7    alternate loggers is available after building the extra components (see
8    the <a href="extras.html">extras components</a> documentation), which includes
9    a full commons-logging implementation.
10  </p>
11  </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>
12  <p>
13    Tomcat 6.0 uses
14    <a href="http://commons.apache.org/logging">Commons Logging</a>
15    throughout its internal code allowing the
16    developer to choose a logging configuration that suits their needs, e.g
17    java.util.logging or
18    <a href="http://logging.apache.org/log4j">Log4J</a>.
19    Commons Logging provides Tomcat the ability to log
20    hierarchially across various log levels without needing to rely on a particular
21    logging implementation.
22  </p>
23  <p>
24    An important consequence for Tomcat 6.0 is that the &lt;Logger&gt; element found in
25    previous versions to create a <code>localhost_log</code> is no longer a valid nested element
26    of &lt;Context&gt;. Instead, the default Tomcat configuration will use java.util.logging.
27    If the developer wishes to collect detailed internal Tomcat logging (i.e what is happening
28    within the Tomcat engine), then they should configure a logging system such as java.util.logging
29    or log4j as detailed next.
30  </p>
31
32  </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>
33    <p>
34      Tomcat 6.0 has done away with <code>localhost_log</code> which you may be familiar with
35      as the runtime exception/stack trace log. These types of error are usually thrown
36      by uncaught exceptions, but are still valuable to the developer. They can now be
37      found in the <code>stdout</code> log.
38    </p>
39
40    <p>
41      If you need to setup cross-context detailed logging from within Tomcat's code,
42      then you can use a simple log4j configuration. Note that this logging van be very
43      verbose depending on the log level you chose to use.  Note also that a log4j logging
44      configuration is not going to produce stack trace type logging: those stack traces
45      are output to <code>stdout</code> as discussed above.
46    </p>
47
48    <p>
49      Follow the following steps to setup a file named tomcat.log that has internal
50      Tomcat logging output to it:
51    </p>
52
53    <p>
54      <ol>
55        <li>Create a file called log4j.properties with the following content
56            and save it into $CATALINA_HOME/lib.
57          <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>
58            log4j.rootLogger=debug, R
59            log4j.appender.R=org.apache.log4j.RollingFileAppender
60            log4j.appender.R.File=${catalina.home}/logs/tomcat.log
61            log4j.appender.R.MaxFileSize=10MB
62            log4j.appender.R.MaxBackupIndex=10
63            log4j.appender.R.layout=org.apache.log4j.PatternLayout
64            log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
65            log4j.logger.org.apache.catalina=DEBUG, R
66          </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>
67  </li>
68
69  <li><a href="http://logging.apache.org/log4j">Download Log4J</a> 
70            (v1.2 or later) and place the log4j jar in $CATALINA_HOME/lib.</li>
71
72        <li>Build the commons-logging additional component using the extras.xml
73        Ant build script which is part of teh Tomcat source bundle.</li>
74       
75        <li>Replace <code>$CATALINA_HOME/bin/tomcat-juli.jar</code> with
76        <code>output/extras/tomcat-juli.jar</code>.</li>
77
78        <li>Place <code>output/extras/tomcat-juli-adapters.jar</code> in
79        $CATALINA_HOME/lib.</li>
80
81  <li>Start Tomcat</li>
82      </ol>
83    </p>
84
85    <p>
86      This log4j configuration sets up a file called tomcat.log in your
87      Tomcat logs folder with a maximum file size of 10MB and
88      up to 10 backups.  DEBUG level is specified which will result in the
89      most verbose output from Tomcat.
90    </p>
91 
92    <p>
93      You can (and should) be more picky about which packages to include
94      in the logging. Tomcat 6 uses defines loggers by Engine and Host names.
95      For example, for a default Catalina localhost log, add this to the
96      end of the log4j.properties above. Note that there are known issues with
97      using this naming convention (with square brackets) in log4j XML based
98      configuration files, so we recommend you use a properties file as described
99      until a future version of log4j allows this convention.
100     
101      <ul>
102        <li>log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R</li>
103  <li>log4j.logger.org.apache.catalina.core=DEBUG, R</li>
104  <li>log4j.logger.org.apache.catalina.session=DEBUG, R</li>
105      </ul>
106
107      Be warned a level of DEBUG will produce megabytes of logging and slow startup
108      of Tomcat. This level should be used sparingly when debugging of internal Tomcat
109      operations is required.
110    </p>
111 
112    <p>
113      Your web applications should certainly use their own log4j configuration.
114      This is valid <i>with</i> the above configuration.  You would place a similar log4j.properties
115      file in your web application's WEB-INF/classes folder, and log4j1.2.8.jar into
116      WEB-INF/lib. Then specify your package level logging. This is a basic setup of log4j
117      which does *not* require Commons-Logging,
118      and you should consult the
119      <a href="http://logging.apache.org/log4j/docs/documentation.html">log4j documentation</a> 
120      for more options.  This page is intended only as a bootstrapping guide.
121    </p>
122 
123  </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>
124
125  <p>
126    The default implemenatation of java.util.logging provided in the JDK is too limited to be
127    useful. A limitation of JDK Logging appears to be the inability to have per-web application logging,
128    as the configuration is per-VM. As a result, Tomcat will, in the default configuration,
129    replace the default LogManager implementation with a container friendly implementation
130    called JULI, which addresses these shortcomings. It supports the same configuration mechanisms
131    as the standard JDK java.util.logging, using either a programmatic approach, or properties
132    files. The main difference is that per-classloader properties files can be set (which enables easy
133    redeployment friendly webapp configuration), and the properties files support slightly extended
134    constructs which allows more freedom for defining handlers and assigning them to loggers.
135  </p>
136  <p>
137    JULI is enabled by default in Tomcat 6.0, and supports per classloader configuration, in addition to
138    the regular global java.util.logging configuration. This means that logging can be configured at
139    the following layers:
140    <ul>
141      <li>In the JDK's logging.properties file. Check
142      your JAVA_HOME environment setting to see which JDK Tomcat is using. The file will be in
143      <code>$JAVA_HOME/jre/lib</code>.
144      Alternately, it can also use a global configuration file located elsewhere by using the
145      system property <code>java.util.logging.config.file</code>, or programmatic configuration using
146      <code>java.util.logging.config.class</code>.</li>
147      <li>In each classloader using a logging.properties file. This means that it is possible to have a
148      configuration for the Tomcat core, as well as separate configurations for each webapps which will
149      have the same lifecycle as the webapps.</li>
150    </ul>
151  </p>
152  <p>
153    The default logging.properties specifies a ConsoleHandler for routing logging to stdout and
154    also a FileHandler. A handler's log level threshold can be set using SEVERE, WARNING, INFO,
155    CONFIG, FINE, FINER, FINEST or ALL. The logging.properties shipped with JDK is set to INFO. You
156    can also target specific packages to collect logging from and specify a level. Here is how
157    you would set debugging from Tomcat. You would need to ensure the ConsoleHandler's level is also
158    set to collect this threshold, so FINEST or ALL should be set. Please refer to Sun's java.util.logging
159    documentation for the complete details.
160  </p>
161  <p>
162    <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>
163  </p>
164  <p>
165    The configuration used by JULI is extremely similar, but uses a few extensions to allow better
166    flexibility in assigning loggers. The main differences are:
167    <ul>
168      <li>A prefix may be added to handler names, so that multiple handlers of a single class may be
169      instantiated. A prefix is a String which starts with a digit, and ends with '.'. For example,
170      <code>22foobar.</code> is a valid prefix.</li>
171      <li>As in Java 5.0, loggers can define a list of handlers using the <code>loggerName.handlers</code>
172      property.</li>
173      <li>By default, loggers will not delegate to their parent if they have associated handlers. This
174      may be changed per logger using the <code>loggerName.useParentHandlers</code> property, which accepts
175      a boolean value.</li>
176      <li>The root logger can define its set of handlers using a <code>.handlers</code> property.</li>
177      <li>System property replacement for property values which start with ${systemPropertyName}.</li>
178    </ul>
179  </p>
180  <p>
181    Example logging.properties file to be placed in $CATALINA_BASE/conf:
182    <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>
183handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, \
184           3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, \
185           java.util.logging.ConsoleHandler
186
187.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
188
189############################################################
190# Handler specific properties.
191# Describes specific configuration info for Handlers.
192############################################################
193
1941catalina.org.apache.juli.FileHandler.level = FINE
1951catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1961catalina.org.apache.juli.FileHandler.prefix = catalina.
197
1982localhost.org.apache.juli.FileHandler.level = FINE
1992localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2002localhost.org.apache.juli.FileHandler.prefix = localhost.
201
2023manager.org.apache.juli.FileHandler.level = FINE
2033manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2043manager.org.apache.juli.FileHandler.prefix = manager.
205
2064admin.org.apache.juli.FileHandler.level = FINE
2074admin.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2084admin.org.apache.juli.FileHandler.prefix = admin.
209
210java.util.logging.ConsoleHandler.level = FINE
211java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
212
213
214############################################################
215# Facility specific properties.
216# Provides extra control for each logger.
217############################################################
218
219org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
220org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = \
221   2localhost.org.apache.juli.FileHandler
222
223org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
224org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = \
225   3manager.org.apache.juli.FileHandler
226
227org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/admin].level = INFO
228org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/admin].handlers = \
229   4admin.org.apache.juli.FileHandler
230
231# For example, set the com.xyz.foo logger to only log SEVERE
232# messages:
233#org.apache.catalina.startup.ContextConfig.level = FINE
234#org.apache.catalina.startup.HostConfig.level = FINE
235#org.apache.catalina.session.ManagerBase.level = FINE
236    </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>
237    </p>
238   
239    <p>
240      Example logging.properties for the servlet-examples web application to be placed
241      in WEB-INF/classes inside the web application:
242      <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>
243handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
244
245############################################################
246# Handler specific properties.
247# Describes specific configuration info for Handlers.
248############################################################
249
250org.apache.juli.FileHandler.level = FINE
251org.apache.juli.FileHandler.directory = ${catalina.base}/logs
252org.apache.juli.FileHandler.prefix = servlet-examples.
253
254java.util.logging.ConsoleHandler.level = FINE
255java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
256      </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>
257    </p>
258
259  </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>
260        Copyright &copy; 1999-2008, Apache Software Foundation
261        </em></font></div></td></tr></table></body></html>
Note: See TracBrowser for help on using the repository browser.