How to enable http access logs in Tomcat

Written by - 0 comments

Published on - Listed in Linux Tomcat


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"
        timestamp="true"/>
      <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"
          pattern="common"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
         directory="logs" prefix="localhost_log." suffix=".txt"
         timestamp="true"/>
        <Context path="/examples" docBase="examples" debug="0"
         reloadable="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
           prefix="localhost_examples_log." suffix=".txt"
           timestamp="true"/>
         </Context>
      </Host>
    </Engine>
  </Service>
</Server> 

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.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Icingaweb   Icingaweb2   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder   


Update cookies preferences