Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

How to enable http access logs in Tomcat
Thursday - Jun 9th 2011 - by - (0 comments)

By default, Tomcat does not write http access logs like the "cousin web server" Apache does it.
But of course Tomcat is able to do so as well as this is a built-in option, which just needs to be enabled in server.xml. To activate such http access logs, the valve classes need to be called. Actually there are several Valve classes, it's just necessary to

a) correctly place the valve either in the or in the element
b) choose the correct valve class for logging (access log in this case)

And this is how a server.xml will look with activated http logging:

<Server port="8005" shutdown="SHUTDOWN" debug="0">
  <Service name="Tomcat-Standalone">
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
      port="8080" minProcessors="5" maxProcessors="75"
      enableLookups="true" redirectPort="8443"
      acceptCount="10" debug="0" connectionTimeout="60000"/>
    <Engine name="Standalone" defaultHost="localhost" debug="0">
      <Logger className="org.apache.catalina.logger.FileLogger"
        prefix="catalina_log." suffix=".txt"
      <Realm className="org.apache.catalina.realm.MemoryRealm" />
      <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve"
          directory="logs" prefix="localhost_access_log." suffix=".txt"

        <Logger className="org.apache.catalina.logger.FileLogger"
         directory="logs" prefix="localhost_log." suffix=".txt"
        <Context path="/examples" docBase="examples" debug="0"
          <Logger className="org.apache.catalina.logger.FileLogger"
           prefix="localhost_examples_log." suffix=".txt"

The above example server.xml was found on this page, which explains all the different server.xml elements in a great way.

Next to the class name "org.apache.catalina.valves.AccessLogValve" there is also the possibility to use the "org.apache.catalina.valves.FastCommonAccessLogValve" class.
This FastCommonAccessLogValve has a better performance and should be used on production systems. Next to the performance, there's another small difference: In FastCommonAccessLogValve only the patterns "common" and "combined" can be used, but this is anyway wanted in most cases.


Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6905 Days
until Death of Computers