Tomcat Logs

You can send your Tomcat application server log files to Loggly using this guide. This guide assumes you use Tomcat 6, 7 or 8, the default java.util.logging logger, and the default log configuration and directories. If not, it will not correctly process multiline stack traces, for that you need to switch to Java Log4j and syslog. For alternatives, please see the Advanced Tomcat Logs Options section.

Tomcat Logging Setup

Automatic Script

  1. Run The Configure Tomcat Script
  2. Run our automatic configure-tomcat script below to setup tomcat logging and send the logs to Loggly through your syslog daemon. Alternatively, you can follow our manual configuration instructions below.

    curl -O https://www.loggly.com/install/configure-tomcat.sh
    sudo bash configure-tomcat.sh -a SUBDOMAIN -u USERNAME
    

    Replace:

    • SUBDOMAIN: your account subdomain that you created when you signed up for Loggly
    • USERNAME: your Loggly username, which is visible at the top right of the Loggly console

    You will need to enter your system root password so it can update your rsyslog configuration. It will then prompt for your Loggly password.

  3. Verify Events
  4. Search Loggly for events with the Tomcat tag over the past hour. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.

    tag:tomcat

    Tomcat Logs

Manual Configuration

  1. Configure Syslog Daemon
  2. If you haven’t already, run our automatic Configure-Syslog script below to setup rsyslog. Alternatively, you can Manually Configure Rsyslog or Syslog-ng.

    curl -O https://www.loggly.com/install/configure-linux.sh
    chmod 755 configure-linux.sh
    sudo ./configure-linux.sh -a SUBDOMAIN -t TOKEN -u USERNAME
    

    Replace:

    • SUBDOMAIN: your account subdomain that you created when you signed up for Loggly
    • TOKEN: your customer token from the source setup page
    • USERNAME: your Loggly username, which is visible at the top right of the Loggly console

  3. Configure Tomcat Logging
  4. It will be easier for rsyslog to find the files without dates in the names. Here’s how you can remove rotation. Open your tomcat log properties file. If you are using tomcat 7 just change the directory to tomcat7.

    sudo vim /etc/tomcat6/logging.properties

    Copy and paste this entire block to replace the handler specific configuration to remove the default log rotation. The lines that are changing have been put in italics.

    1catalina.org.apache.juli.FileHandler.level = FINE
    1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
    1catalina.org.apache.juli.FileHandler.prefix = catalina
    1catalina.org.apache.juli.FileHandler.rotatable = false
    
    2localhost.org.apache.juli.FileHandler.level = FINE
    2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
    2localhost.org.apache.juli.FileHandler.prefix = localhost
    2localhost.org.apache.juli.FileHandler.rotatable = false
    
    3manager.org.apache.juli.FileHandler.level = FINE
    3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
    3manager.org.apache.juli.FileHandler.prefix = manager
    3manager.org.apache.juli.FileHandler.rotatable = false
    
    4host-manager.org.apache.juli.FileHandler.level = FINE
    4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
    4host-manager.org.apache.juli.FileHandler.prefix = host-manager
    4host-manager.org.apache.juli.FileHandler.rotatable = false

    Tomcat Config
    Setup Tomcat Access Logs

    You can forward Tomcat access logs to Loggly by enabling the Access logs in server.xml located at /etc/tomcat6/server.xml. Disable the log rotation in the following section in the server.xml and remove ‘.’ from “localhost_access_log.” if there is any.

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t "%r" %s %b"/>

    Add the following attribute to the above Valve tag to stop the log rotation.

    renameOnRotate="true"

    Restart tomcat

    $ sudo service tomcat6 restart

  5. Setup Tomcat Log File Monitoring
  6. Copy this to your terminal window and run it. It will make sure the working directory exists. If it’s an Ubuntu system, it will set the proper permissions. It will then open a tomcat configuration file.

    sudo mkdir -v /var/spool/rsyslog
    if [ "$(lsb_release -ds | grep Ubuntu)" != "" ]; then
       sudo chown -R syslog:adm /var/spool/rsyslog
    fi
    sudo vim /etc/rsyslog.d/21-tomcat-loggly.conf
    

    Paste in the following configuration and replace your customer token:

    $ModLoad imfile
    $InputFilePollInterval 10
    $WorkDirectory /var/spool/rsyslog
    $PrivDropToGroup adm
    $WorkDirectory /var/spool/rsyslog
    
    #Add a tag for tomcat events
    $template LogglyFormatTomcat,"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [TOKEN@41058 tag=\"tomcat\"] %msg%\n"
    
    # catalina.log
    $InputFileName /var/log/tomcat6/catalina.log
    $InputFileTag catalina-log
    $InputFileStateFile stat-catalina-log
    $InputFileSeverity info
    $InputFilePersistStateInterval 20000
    $InputRunFileMonitor
    if $programname == 'catalina-log' then @@logs-01.loggly.com:514;LogglyFormatTomcat
    if $programname == 'catalina-log' then ~
    
    # catalina.out
    $InputFileName /var/log/tomcat6/catalina.out
    $InputFileTag catalina-out
    $InputFileStateFile stat-catalina-out
    $InputFileSeverity info
    $InputFilePersistStateInterval 20000
    $InputRunFileMonitor
    if $programname == 'catalina-out' then @@logs-01.loggly.com:514;LogglyFormatTomcat
    if $programname == 'catalina-out' then ~
    
    # host-manager.log
    $InputFileName /var/log/tomcat6/host-manager.log
    $InputFileTag host-manager
    $InputFileStateFile stat-host-manager
    $InputFileSeverity info
    $InputFilePersistStateInterval 20000
    $InputRunFileMonitor
    if $programname == 'host-manager' then @@logs-01.loggly.com:514;LogglyFormatTomcat
    if $programname == 'host-manager' then ~
    
    # initd.log
    $InputFileName /var/log/tomcat6/initd.log
    $InputFileTag initd
    $InputFileStateFile stat-initd
    $InputFileSeverity info
    $InputFilePersistStateInterval 20000
    $InputRunFileMonitor
    if $programname == 'initd' then @@logs-01.loggly.com:514;LogglyFormatTomcat
    if $programname == 'initd' then ~
    
    # localhost.log
    $InputFileName /var/log/tomcat6/localhost.log
    $InputFileTag localhost-log
    $InputFileStateFile stat-localhost-log
    $InputFileSeverity info
    $InputFilePersistStateInterval 20000
    $InputRunFileMonitor
    if $programname == 'localhost-log' then @@logs-01.loggly.com:514;LogglyFormatTomcat
    if $programname == 'localhost-log' then ~
    
    # manager.log
    $InputFileName /var/log/tomcat6/manager.log
    $InputFileTag manager
    $InputFileStateFile stat-manager
    $InputFileSeverity info
    $InputFilePersistStateInterval 20000
    $InputRunFileMonitor
    if $programname == 'manager' then @@logs-01.loggly.com:514;LogglyFormatTomcat
    if $programname == 'manager' then ~
    
    # localhost_access_log.txt 
    $InputFileName /var/lib/tomcat6/logs/localhost_access_log.txt 
    $InputFileTag tomcat-access 
    $InputFileStateFile stat-tomcat-access 
    $InputFileSeverity info 
    $InputFilePersistStateInterval 20000 
    $InputRunFileMonitor 
    if $programname == 'tomcat-access' then @@logs-01.loggly.com:514;LogglyFormatTomcat 
    if $programname == 'tomcat-access' then ~ 

    Restart rsyslog

    $ sudo service rsyslog restart

  7. Verify Events
  8. Search Loggly for events with the Tomcat tag over the past hour. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.

    tag:tomcat

    Tomcat Logging

Advanced Tomcat Logging Options

  • Tomcat 8 – Send tomcat 8 logs to loggly using configure-tomcat script by providing $CATALINA_HOME path under -ch option.
  • Java Log4j Logs – Send logs from Tomcat using Log4j
  • Script Source on GitHub – View the source or suggest improvements
  • Search or post your own Tomcat logs questions in the community forum or read more about what is Tomcat here.

Troubleshooting Tomcat Logs

If you don’t see any data show up in the verification step, then check for these common problems.

Check Tomcat:

  • Wait a few minutes in case indexing needs to catch up
  • Check the tomcat log files to make sure they exist and you have the right path and permissions
  • Try sending a test log with a tomcat tag: logger -t catalina-log test

Check Your Syslog Daemon:

Still Not Working?

Thanks for the feedback! We'll use it to improve our support documentation.


Top