blob: 040a6fcb6e33572558a75b7c6f1cf560c28f6a8b [file] [log] [blame]
Cheng Tang07b30872014-04-27 16:37:18 +08001<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 7 (7.0.42) - Logging in Tomcat</title><meta name="author" content="Allistair Crossley"><meta name="author" content="Yoav Shapira"><style type="text/css" media="print">
2 .noPrint {display: none;}
3 td#mainBody {width: 100%;}
4 </style><style type="text/css">
5 code {background-color:rgb(224,255,255);padding:0 0.1em;}
6 code.attributeName, code.propertyName {background-color:transparent;}
7 </style><style type="text/css">
8 .wrapped-source code { display: block; background-color: transparent; }
9 .wrapped-source div { margin: 0 0 0 1.25em; }
10 .wrapped-source p { margin: 0 0 0 1.25em; text-indent: -1.25em; }
11 </style><style type="text/css">
12 p.notice {
13 border: 1px solid rgb(255, 0, 0);
14 background-color: rgb(238, 238, 238);
15 color: rgb(0, 51, 102);
16 padding: 0.5em;
17 margin: 1em 2em 1em 1em;
18 }
19 </style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="./images/tomcat.gif" align="right" alt="
20 The Apache Tomcat Servlet/JSP Container
21 " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.42, Jul 2 2013</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="./images/asf-logo.gif" align="right" alt="Apache Logo" border="0"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><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><li><a href="#comments_section">User Comments</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><li><a href="security-howto.html">28) Security Considerations</a></li><li><a href="windows-service-howto.html">29) Windows Service</a></li><li><a href="windows-auth-howto.html">30) Windows Authentication</a></li><li><a href="jdbc-pool.html">31) Tomcat's JDBC Pool</a></li><li><a href="web-socket-howto.html">32) WebSocket</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">Tomcat Javadocs</a></li><li><a href="servletapi/index.html">Servlet Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.2 Javadocs</a></li><li><a href="elapi/index.html">EL 2.2 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><li><a href="tribes/introduction.html">Tribes</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Logging in Tomcat</h1><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
22<ul><li><a href="#Introduction">Introduction</a><ol><li><a href="#Java_logging_API_%E2%80%94_java.util.logging">Java logging API &mdash; java.util.logging</a></li><li><a href="#Servlets_logging_API">Servlets logging API</a></li><li><a href="#Console">Console</a></li><li><a href="#Access_logging">Access logging</a></li></ol></li><li><a href="#Using_java.util.logging_(default)">Using java.util.logging (default)</a><ol><li><a href="#Documentation_references">Documentation references</a></li><li><a href="#Considerations_for_productive_usage">Considerations for productive usage</a></li></ol></li><li><a href="#Using_Log4j">Using Log4j</a></li></ul>
23</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
24 <p>
25 Logging in Apache Tomcat is implemented with the help of
26 <a href="http://commons.apache.org/logging">Apache Commons Logging</a>
27 library. That library is a thin wrapper above different logging
28 frameworks. It provides Tomcat with the ability to log
29 hierarchically across various log levels without the need to rely on a
30 particular logging implementation.
31 </p>
32
33 <p>
34 Since Tomcat 6.0, Tomcat uses a private package-renamed implementation of
35 Apache Commons Logging, to allow web applications to use their own
36 independent copies of the original Apache Commons Logging library.
37 In the default distribution this private copy of the library
38 is simplified and hardcoded to use the <code>java.util.logging</code> framework.
39 </p>
40
41 <p>
42 To configure Tomcat to use alternative logging frameworks for its internal
43 logging, one has to replace the logging library with the one that is built
44 with the full implementation. Such library is provided as an <a href="extras.html">extras</a>
45 component. Instructions on how to configure Tomcat to use Log4j framework
46 for its internal logging may be found below.
47 </p>
48
49 <p>
50 A web application running on Apache Tomcat can:
51 </p>
52 <ul>
53 <li>
54 Use system logging API, <code>java.util.logging</code>.
55 </li>
56 <li>
57 Use the logging API provided by the Java Servlets specification,
58 <code>javax.servlet.ServletContext.log(...)</code>
59 </li>
60 <li>
61 Use any logging framework of its choice.
62 </li>
63 </ul>
64
65 <p>
66 The logging frameworks used by different web applications run independently
67 of each other. See <a href="class-loader-howto.html">class loading</a>
68 for more details.
69 The exception to this rule is <code>java.util.logging</code>, if it used
70 directly or indirectly by your logging library. That is because it is loaded
71 by the system and is shared across web applications.
72 </p>
73
74 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Java logging API %E2%80%94 java.util.logging"><!--()--></a><a name="Java_logging_API_%E2%80%94_java.util.logging"><strong>Java logging API &mdash; java.util.logging</strong></a></font></td></tr><tr><td><blockquote>
75
76 <p>
77 Apache Tomcat has its own implementation of several key elements of
78 <code>java.util.logging</code> API. This implementation is called "JULI".
79 The key component there is a custom LogManager implementation,
80 that is aware of different web applications running on Tomcat (and
81 their different class loaders). It supports private per-application
82 logging configurations. It is also notified by Tomcat when a web application
83 is unloaded from memory, so that the references to its classes can be
84 cleared, preventing memory leaks.
85 </p>
86
87 <p>
88 This <code>java.util.logging</code> implementation is enabled by providing
89 certain system properties when starting Java. The Apache Tomcat startup
90 scripts do this for you, but if you are using different tools to run
91 Tomcat (such as jsvc, or running Tomcat from within an IDE), you should
92 take care of them by yourself.
93 </p>
94
95 <p>
96 More details about java.util.logging may be found in the documentation
97 for your JDK and on its Javadoc pages for the <code>java.util.logging</code>
98 package.
99 </p>
100
101 <p>
102 More details about Tomcat JULI may be found below.
103 </p>
104
105 </blockquote></td></tr></table>
106
107 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Servlets logging API"><!--()--></a><a name="Servlets_logging_API"><strong>Servlets logging API</strong></a></font></td></tr><tr><td><blockquote>
108
109 <p>
110 The calls to <code>javax.servlet.ServletContext.log(...)</code> to write
111 log messages are handled by internal Tomcat logging. Such messages are
112 logged to the category named
113 </p>
114 <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>org.apache.catalina.core.ContainerBase.[${engine}].[${host}].[${context}]</pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
115 <p>
116 This logging is performed according to the Tomcat logging configuration. You
117 cannot overwrite it in a web application.
118 </p>
119
120 <p>
121 The Servlets logging API predates the <code>java.util.logging</code> API
122 that is now provided by Java. As such, it does not offer you much options.
123 E.g., you cannot control the log levels. It can be noted, though, that
124 in Apache Tomcat implementation the calls to <code>ServletContext.log(String)</code>
125 or <code>GenericServlet.log(String)</code> are logged at the INFO level.
126 The calls to <code>ServletContext.log(String, Throwable)</code> or
127 <code>GenericServlet.log(String, Throwable)</code>
128 are logged at the ERROR level.
129 </p>
130
131 </blockquote></td></tr></table>
132
133 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Console"><strong>Console</strong></a></font></td></tr><tr><td><blockquote>
134
135 <p>
136 When running Tomcat on unixes, the console output is usually redirected
137 to the file named <code>catalina.out</code>. The name is configurable
138 using an environment variable. (See the startup scripts).
139 Whatever is written to <code>System.err/out</code> will be caught into
140 that file. That may include:
141 </p>
142
143 <ul>
144 <li>Uncaught exceptions printed by <code>java.lang.ThreadGroup.uncaughtException(..)</code></li>
145 <li>Thread dumps, if you requested them via a system signal</li>
146 </ul>
147
148 <p>
149 When running as a service on Windows, the console output is also caught
150 and redirected, but the file names are different.
151 </p>
152
153 <p>
154 The default logging configuration in Apache Tomcat writes the same
155 messages to the console and to a log file. This is great when using
156 Tomcat for development, but usually is not needed in production.
157 </p>
158
159 <p>
160 Old applications that still use <code>System.out</code> or <code>System.err</code>
161 can be tricked by setting <code>swallowOutput</code> attribute on a
162 <a href="config/context.html">Context</a>. If the attribute is set to
163 <code>true</code>, the calls to <code>System.out/err</code> during request
164 processing will be intercepted, and their output will be fed to the
165 logging subsystem using the
166 <code>javax.servlet.ServletContext.log(...)</code> calls.<br>
167 <strong>Note</strong>, that the <code>swallowOutput</code> feature is
168 actually a trick, and it has its limitations.
169 It works only with direct calls to <code>System.out/err</code>,
170 and only during request processing cycle. It may not work in other
171 threads that might be created by the application. It cannot be used to
172 intercept logging frameworks that themselves write to the system streams,
173 as those start early and may obtain a direct reference to the streams
174 before the redirection takes place.
175 </p>
176
177 </blockquote></td></tr></table>
178
179 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Access logging"><!--()--></a><a name="Access_logging"><strong>Access logging</strong></a></font></td></tr><tr><td><blockquote>
180
181 <p>
182 A related, but different feature is access logging. It can be configured
183 as a valve at the Context, or Host, or Engine. See <a href="config/valve.html">Valves</a>
184 documentation for more details.
185 </p>
186
187 </blockquote></td></tr></table>
188
189 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Using java.util.logging (default)"><!--()--></a><a name="Using_java.util.logging_(default)"><strong>Using java.util.logging (default)</strong></a></font></td></tr><tr><td><blockquote>
190
191 <p>
192 The default implementation of java.util.logging provided in the JDK is too
193 limited to be useful. A limitation of JDK Logging appears to be the
194 inability to have per-web application logging, as the configuration is
195 per-VM. As a result, Tomcat will, in the default configuration, replace the
196 default LogManager implementation with a container friendly implementation
197 called JULI, which addresses these shortcomings. It supports the same
198 configuration mechanisms as the standard JDK java.util.logging, using either
199 a programmatic approach, or properties files. The main difference is that
200 per-classloader properties files can be set (which enables easy redeployment
201 friendly webapp configuration), and the properties files support slightly
202 extended constructs which allows more freedom for defining handlers and
203 assigning them to loggers.
204 </p>
205 <p>
206 JULI is enabled by default, and supports per classloader configuration, in
207 addition to the regular global java.util.logging configuration. This means
208 that logging can be configured at the following layers:
209 <ul>
210 <li>Globally. That is usually done in the
211 <code>${catalina.base}/conf/logging.properties</code> file.
212 The file is specified by the <code>java.util.logging.config.file</code>
213 System property which is set by the startup scripts.
214 If it is not readable or is not configured, the default is to use the
215 <code>${java.home}/lib/logging.properties</code> file in the JRE.
216 </li>
217 <li>In the web application. The file will be
218 <code>WEB-INF/classes/logging.properties</code>
219 </li>
220 </ul>
221 </p>
222 <p>
223 The default <code>logging.properties</code> in the JRE specifies a
224 <code>ConsoleHandler</code> that routes logging to System.err.
225 The default <code>conf/logging.properties</code> in Apache Tomcat also
226 adds several <code>FileHandler</code>s that write to files.
227 </p>
228 <p>
229 A handler's log level threshold is INFO by default and can be set using
230 SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST or ALL.
231 You can also target specific packages to collect logging from and specify
232 a level.
233 </p>
234 <p>
235 Here is how you would set debugging from Tomcat. You would need to ensure the
236 ConsoleHandler's (or FileHandler's') level is also set to collect this threshold,
237 so FINEST or ALL should be set. Please refer to <code>java.util.logging</code>
238 documentation in the JDK for the complete details:
239 </p>
240 <p>
241 <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>org.apache.catalina.level=FINEST</pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
242 </p>
243 <p>
244 The configuration used by JULI is extremely similar to the one supported by
245 plain <code>java.util.logging</code>, but uses a few
246 extensions to allow better flexibility in assigning loggers. The main
247 differences are:
248 </p>
249 <ul>
250 <li>A prefix may be added to handler names, so that multiple handlers of a
251 single class may be instantiated. A prefix is a String which starts with a
252 digit, and ends with '.'. For example, <code>22foobar.</code> is a valid
253 prefix.</li>
254 <li>System property replacement is performed for property values which
255 contain ${systemPropertyName}.</li>
256 <li>As in Java 6, loggers can define a list of handlers using the
257 <code>loggerName.handlers</code> property.</li>
258 <li>By default, loggers will not delegate to their parent if they have
259 associated handlers. This may be changed per logger using the
260 <code>loggerName.useParentHandlers</code> property, which accepts a
261 boolean value.</li>
262 <li>The root logger can define its set of handlers using the
263 <code>.handlers</code> property.</li>
264 </ul>
265 <p>
266 There are several additional implementation classes, that can be used
267 together with the ones provided by Java. The notable one is
268 <code>org.apache.juli.FileHandler</code>.
269 </p>
270 <p>
271 <code>org.apache.juli.FileHandler</code> supports buffering of the
272 logs. The buffering is not enabled by default. To configure it, use the
273 <code>bufferSize</code> property of a handler. The value of <code>0</code>
274 uses system default buffering (typically an 8K buffer will be used). A
275 value of <code>&lt;0</code> forces a writer flush upon each log write. A
276 value <code>&gt;0</code> uses a BufferedOutputStream with the defined
277 value but note that the system default buffering will also be
278 applied.
279 </p>
280 <p>
281 Example logging.properties file to be placed in $CATALINA_BASE/conf:
282 <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
283handlers = 1catalina.org.apache.juli.FileHandler, \
284 2localhost.org.apache.juli.FileHandler, \
285 3manager.org.apache.juli.FileHandler, \
286 java.util.logging.ConsoleHandler
287
288.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
289
290############################################################
291# Handler specific properties.
292# Describes specific configuration info for Handlers.
293############################################################
294
2951catalina.org.apache.juli.FileHandler.level = FINE
2961catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2971catalina.org.apache.juli.FileHandler.prefix = catalina.
298
2992localhost.org.apache.juli.FileHandler.level = FINE
3002localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3012localhost.org.apache.juli.FileHandler.prefix = localhost.
302
3033manager.org.apache.juli.FileHandler.level = FINE
3043manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3053manager.org.apache.juli.FileHandler.prefix = manager.
3063manager.org.apache.juli.FileHandler.bufferSize = 16384
307
308java.util.logging.ConsoleHandler.level = FINE
309java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
310
311
312############################################################
313# Facility specific properties.
314# Provides extra control for each logger.
315############################################################
316
317org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
318org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = \
319 2localhost.org.apache.juli.FileHandler
320
321org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
322org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = \
323 3manager.org.apache.juli.FileHandler
324
325# For example, set the org.apache.catalina.util.LifecycleBase logger to log
326# each component that extends LifecycleBase changing state:
327#org.apache.catalina.util.LifecycleBase.level = FINE
328</pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
329 </p>
330
331 <p>
332 Example logging.properties for the servlet-examples web application to be
333 placed in WEB-INF/classes inside the web application:
334 <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
335handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
336
337############################################################
338# Handler specific properties.
339# Describes specific configuration info for Handlers.
340############################################################
341
342org.apache.juli.FileHandler.level = FINE
343org.apache.juli.FileHandler.directory = ${catalina.base}/logs
344org.apache.juli.FileHandler.prefix = servlet-examples.
345
346java.util.logging.ConsoleHandler.level = FINE
347java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
348</pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
349 </p>
350
351 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Documentation references"><!--()--></a><a name="Documentation_references"><strong>Documentation references</strong></a></font></td></tr><tr><td><blockquote>
352 <p>See the following resources for additional information:</p>
353 <ul>
354 <li>Apache Tomcat Javadoc for the
355 <a href="api/org/apache/juli/package-summary.html"><code>org.apache.juli</code></a>
356 package.
357 </li>
358 <li>Oracle Java 6 Javadoc for the
359 <a href="http://docs.oracle.com/javase/6/docs/api/java/util/logging/package-summary.html"><code>java.util.logging</code></a>
360 package.
361 </li>
362 </ul>
363 </blockquote></td></tr></table>
364
365 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Considerations for productive usage"><!--()--></a><a name="Considerations_for_productive_usage"><strong>Considerations for productive usage</strong></a></font></td></tr><tr><td><blockquote>
366 <p>You may want to take note of the following:</p>
367 <ul>
368 <li><p>Consider removing <code>ConsoleHandler</code> from configuration.</p>
369 <p>By default (thanks to the <code>.handlers</code> setting) logging goes
370 both to a <code>FileHandler</code> and to a <code>ConsoleHandler</code>.
371 The output of the latter one is usually captured into a file, such as
372 <code>catalina.out</code>. Thus you end up with two copies of the same
373 messages.</p>
374 </li>
375 <li><p>Consider removing <code>FileHandler</code>s for the applications
376 that you do not use. E.g., the one for <code>host-manager</code>.</p></li>
377 <li><p>The handlers by default use the system default encoding to write
378 the log files. It can be configured with <code>encoding</code> property.
379 See Javadoc for details.</p></li>
380 <li><p>Consider configuring an <a href="config/valve.html">Access
381 log</a>.</p></li>
382 </ul>
383 </blockquote></td></tr></table>
384
385 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Using Log4j"><!--()--></a><a name="Using_Log4j"><strong>Using Log4j</strong></a></font></td></tr><tr><td><blockquote>
386 <p>
387 This section explains how to configure Tomcat to use
388 <a href="http://logging.apache.org/log4j/">log4j</a> rather than
389 java.util.logging for all Tomcat's internal logging.
390 </p>
391 <p><em>Note</em>: The steps described in this section are needed
392 when you want to reconfigure Tomcat to use Apache log4j for its own
393 logging. These steps are <strong>not</strong> needed if you just want
394 to use log4j in your own web application. &mdash; In that case, just
395 put <code>log4j.jar</code> and <code>log4j.properties</code> into
396 <code>WEB-INF/lib</code> and <code>WEB-INF/classes</code>
397 of your web application.
398 </p>
399 <p>
400 The following steps describe configuring log4j to output Tomcat's
401 internal logging.
402 </p>
403
404 <ol>
405 <li>Create a file called <code>log4j.properties</code> with the
406 following content and save it into <code>$CATALINA_BASE/lib</code></li>
407 </ol>
408 <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
409log4j.rootLogger=INFO, CATALINA
410
411# Define all the appenders
412log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
413log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.
414log4j.appender.CATALINA.Append=true
415log4j.appender.CATALINA.Encoding=UTF-8
416# Roll-over the log once per day
417log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log'
418log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
419log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
420
421log4j.appender.LOCALHOST=org.apache.log4j.DailyRollingFileAppender
422log4j.appender.LOCALHOST.File=${catalina.base}/logs/localhost.
423log4j.appender.LOCALHOST.Append=true
424log4j.appender.LOCALHOST.Encoding=UTF-8
425log4j.appender.LOCALHOST.DatePattern='.'yyyy-MM-dd'.log'
426log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
427log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
428
429log4j.appender.MANAGER=org.apache.log4j.DailyRollingFileAppender
430log4j.appender.MANAGER.File=${catalina.base}/logs/manager.
431log4j.appender.MANAGER.Append=true
432log4j.appender.MANAGER.Encoding=UTF-8
433log4j.appender.MANAGER.DatePattern='.'yyyy-MM-dd'.log'
434log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
435log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
436
437log4j.appender.HOST-MANAGER=org.apache.log4j.DailyRollingFileAppender
438log4j.appender.HOST-MANAGER.File=${catalina.base}/logs/host-manager.
439log4j.appender.HOST-MANAGER.Append=true
440log4j.appender.HOST-MANAGER.Encoding=UTF-8
441log4j.appender.HOST-MANAGER.DatePattern='.'yyyy-MM-dd'.log'
442log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
443log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
444
445log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
446log4j.appender.CONSOLE.Encoding=UTF-8
447log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
448log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
449
450# Configure which loggers log to which appenders
451log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, LOCALHOST
452log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]=\
453 INFO, MANAGER
454log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]=\
455 INFO, HOST-MANAGER
456</pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
457 <ol start="2">
458 <li><a href="http://logging.apache.org/log4j">Download Log4J</a>
459 (v1.2 or later).</li>
460
461 <li><p>Download or build <code>tomcat-juli.jar</code> and
462 <code>tomcat-juli-adapters.jar</code> that are available as an "extras"
463 component for Tomcat. See <a href="extras.html">Additional Components
464 documentation</a> for details.</p>
465 <p>This <code>tomcat-juli.jar</code> differs from the default one. It
466 contains the full Apache Commons Logging implementation and thus is
467 able to discover the presense of log4j and configure itself.</p>
468 </li>
469
470 <li><p>If you want to configure Tomcat to use log4j globally:</p>
471 <ul>
472 <li>Put <code>log4j.jar</code> and
473 <code>tomcat-juli-adapters.jar</code> from "extras" into
474 <code>$CATALINA_HOME/lib</code>.</li>
475 <li>Replace <code>$CATALINA_HOME/bin/tomcat-juli.jar</code> with
476 <code>tomcat-juli.jar</code> from "extras".</li>
477 </ul>
478 </li>
479
480 <li><p>If you are running Tomcat with separate $CATALINA_HOME and
481 $CATALINA_BASE and want to configure to use log4j in a single
482 $CATALINA_BASE only:</p>
483 <ul>
484 <li>Create <code>$CATALINA_BASE/bin</code> and
485 <code>$CATALINA_BASE/lib</code> directories if they do not exist.
486 </li>
487 <li>Put <code>log4j.jar</code> and
488 <code>tomcat-juli-adapters.jar</code> from "extras" into
489 <code>$CATALINA_BASE/lib</code></li>
490 <li>Put <code>tomcat-juli.jar</code> from "extras" as
491 <code>$CATALINA_BASE/bin/tomcat-juli.jar</code></li>
492 <li>If you are running with a
493 <a href="security-manager-howto.html">security manager</a>, you
494 would need to edit the
495 <code>$CATALINA_BASE/conf/catalina.policy</code> file to adjust
496 it to using a different copy of tomcat-juli.jar.</li>
497 </ul>
498 </li>
499
500 <li><p>Delete <code>$CATALINA_BASE/conf/logging.properties</code> to
501 prevent java.util.logging generating zero length log files.</p></li>
502
503 <li><p>Start Tomcat</p></li>
504 </ol>
505
506 <p>
507 This log4j configuration mirrors the default java.util.logging setup
508 that ships with Tomcat: both the manager and host-manager apps get an
509 individual log file, and everything else goes to the "catalina.log" log
510 file. Each file is rolled-over once per day.
511 </p>
512
513 <p>
514 You can (and should) be more picky about which packages to include
515 in the logging. Tomcat defines loggers by Engine and Host names.
516 For example, for a more detailed Catalina localhost log, add this to the
517 end of the log4j.properties above. Note that there are known issues with
518 using this naming convention (with square brackets) in log4j XML based
519 configuration files, so we recommend you use a properties file as
520 described until a future version of log4j allows this convention.
521 </p>
522 <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
523log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG
524log4j.logger.org.apache.catalina.core=DEBUG
525log4j.logger.org.apache.catalina.session=DEBUG
526</pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
527
528 <p>
529 Be warned: a level of DEBUG will produce megabytes of logging and slow
530 startup of Tomcat. This level should be used sparingly when debugging of
531 internal Tomcat operations is required.
532 </p>
533
534 <p>
535 Your web applications should certainly use their own log4j configuration.
536 This is valid <i>with</i> the above configuration. You would place a
537 similar log4j.properties file in your web application's WEB-INF/classes
538 directory, and log4jx.y.z.jar into WEB-INF/lib. Then specify your package
539 level logging. This is a basic setup of log4j which does *not* require
540 Commons-Logging, and you should consult the
541 <a href="http://logging.apache.org/log4j/docs/documentation.html">log4j
542 documentation</a> for more options. This page is intended only as a
543 bootstrapping guide.
544 </p>
545
546 <p><em>Additional notes</em></p>
547 <ul>
548 <li><p>This exposes log4j libraries to the web applications through the
549 Common classloader. See <a href="class-loader-howto.html">class loading</a>
550 documentation for details.</p>
551 <p>Because of that, the web applications and libraries using
552 <a href="http://commons.apache.org/logging">Apache Commons Logging</a>
553 library are likely to automatically choose log4j as the underlying
554 logging implementation.</p></li>
555
556 <li><p>The <code>java.util.logging</code> API is still available, for
557 those web applications that use it directly. The
558 <code>${catalina.base}/conf/logging.properties</code> file is still
559 referenced by Tomcat startup scripts.</p>
560 <p> Removal of <code>${catalina.base}/conf/logging.properties</code>
561 file, mentioned as one of the steps, just causes
562 <code>java.util.logging</code> to fallback to the default configuration
563 as configured in JRE, which is to use a ConsoleHandler and do not
564 create any files.</p></li>
565 </ul>
566 </blockquote></td></tr></table></td></tr><tr class="noPrint"><td width="20%" valign="top" nowrap class="noPrint"></td><td width="80%" valign="top" align="left"><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="comments_section" id="comments_section"><strong>Comments</strong></a></font></td></tr><tr><td><blockquote><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
567 on improving documentation for Apache Tomcat.<br><br>
568 If you have trouble and need help, read
569 <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
570 and ask your question on the tomcat-users
571 <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
572 Do not ask such questions here. This is not a Q&amp;A section.<br><br>
573 The Apache Comments System is explained <a href="/tomcat-7.0-doc/comments.html">here</a>.
574 Comments may be removed by our moderators if they are either
575 implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
576 var comments_shortname = 'tomcat';
577 var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/logging.html';
578 (function(w, d) {
579 if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
580 d.write('<div id="comments_thread"><\/div>');
581 var s = d.createElement('script');
582 s.type = 'text/javascript';
583 s.async = true;
584 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
585 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
586 }
587 else {
588 d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
589 }
590 })(window, document);
591 //--><!]]></script></blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
592 Copyright &copy; 1999-2013, Apache Software Foundation
593 </em></font></div></td></tr></table></body></html>