tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Tomcat Wiki] Update of "FAQ/Logging" by GianlucaVarisco
Date Wed, 28 Nov 2007 19:10:06 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tomcat Wiki" for change notification.

The following page has been changed by GianlucaVarisco:
http://wiki.apache.org/tomcat/FAQ/Logging

New page:
== Preface ==
This FAQ section provides help with logging-related issues.

As you read these questions, please keep in mind that Tomcat's internal logging is separate
from your own webapp's logging. You would typically be concerned only with your own webapp's
logging. You would modify Tomcat's internal logging settings if you are debugging a possible
issue or running into other problems. It is anticipated that Tomcat's out-of-the-box logging
configuration will be fine for the vast majority of users and environments.

== Questions ==

'''Does Tomcat have built-in logging capabilities, and if so how do I use them?'''

The Servlet Specification requires Servlet Containers like Tomcat to provide at least a rudimentary
implementation of the ServletContext#log method. Tomcat provides a much richer implementation
than required by the Spec, as follows:

 * Prior to Tomcat 5.5, Tomcat provided a Logger element that you could configure and extend
according to your needs. If you are using a Tomcat version previous to Tomcat 5.5, make sure
to read the [http://tomcat.apache.org/tomcat-5.0-doc/config/logger.html Logger configuration
reference].
 * Starting with Tomcat 5.5, Logger was removed and [http://jakarta.apache.org/commons/logging
Jakarta Commons-Logging] {{{Log}}} is used everywhere in Tomcat. Read the Commons-Logging
documentation if you'd like to know how to better use and configure Tomcat's internal logging.

In addition, Tomcat does not swallow the System.out and System.err JVM output streams. You
may use these streams for elementary logging if you wish, but a more robust approach such
as commons-logging or [http://logging.apache.org/log4j Log4J] is recommended for production
applications.

'''How do I configure commons-logging for use with Tomcat?'''

You need to specify a commons-logging configuration file and, if you wish, a logging implementation
that supports commons-logging. JDK 1.4 (and later) java.util.Logging and Log4j are the two
most commonly used logging toolkits for Tomcat. If you supply an external logging toolkit
such as Log4J, it needs to be located in the $CATALINA_HOME/common/lib directory (for Tomcat
5.0 and earlier) or added to the bootstrap classpath by using the scripts in $CATALINA_HOME/bin
(this is required for Tomcat 5.5 and later, which uses commons-logging while bootstrapping,
and optional for Tomcat 5.0 and earlier).

For more detailed instructions, see these mailing list discussions:

 * [http://marc.theaimsgroup.com/?l=tomcat-user&m=106623436423859&w=2 A log4j example]
 * [http://marc.theaimsgroup.com/?l=tomcat-user&m=108330970225012&w=2 Logging Configuration]
 * [http://marc.theaimsgroup.com/?l=tomcat-user&m=108578233003073&w=2 Example with
JSVC and running on port 80.]
 * [http://mail-archives.apache.org/eyebrowse/BrowseList?listName=tomcat-user@jakarta.apache.org&by=thread&from=877025
Need for it to be in bootstrap classpath.]

'''How should I log in my own webapps?'''

While you can use System.out and System.err to log, we strongly recommend using a toolkit
like Log4J or JDK 1.4's java.util.logging package. With these toolkits, you have significantly
more functionality (for example, sending emails, logging to a database, controlling at runtime
the logging level of different classes, inspecting the logs with a graphical viewer, etc.)
than with Tomcat's built-in default logging configuration.

We also recommend that you separate your logging from Tomcat's internal logging. That means
you should bundle your logging toolkit with your webapp. If you're using Log4J, for example,
place the Log4J jar in the WEB-INF/lib directory of your webapp and the Log4J configuration
file in the WEB-INF/classes directory of your webapp. This way different web applications
can have different logging configurations and you don't need to worry about them interfering
with each other.

'''Where does System.out go? How do I rotate catalina.out?'''

System.out and System.err both print to catalina.out. But you can suppress this via the swallowOutput
property and sent to different log files.
catalina.out does not rotate. But it should not be an issue because nothing should be printing
to standard output since you are using a logging package, right? [http://marc.theaimsgroup.com/?t=105544472600001&r=1&w=2a
thread about rotation of catalina.out]

'''Where are the logs when running Tomcat as a Windows service?'''

See these mailing list archive threads:

 * [http://mail-archives.apache.org/eyebrowse/BrowseList?listName=tomcat-user@jakarta.apache.org&by=thread&from=863525Where
are the Tomcat logs when running as a Windows service?]

'''Are there external documents, tutorials, or references about logging in Tomcat?'''

Yes, there are. You can Google for more, but some such references are:

 * [http://minaret.biz/tips/tomcatLogging.html Tomcat 5.0.27, Velocity 1.4, Log4j]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message