Documentation forLoggly

Tomcat Logs

Loggly provides the infrastructure to aggregate and normalize log events so they are available to explore interactively, build visualizations, or create threshold-based alerting. In general, any method to send logs from a system or application to an external source can be adapted to send logs to Loggly. The following instructions provide one scenario for sending logs to Loggly.

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

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.

2. Verify Events

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 Log Example

Manual Configuration

1. Configure Syslog Daemon

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

2. Configure Tomcat Logging

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 

3. Setup Tomcat Log File Monitoring

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 

4. Verify Events

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 Example

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 .

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:

SELinux Error:

  • Sample Error Messages:
    ERROR: selinux status is 'Enforcing'. Please manually restart the rsyslog daemon or turn off selinux by running 'setenforce 0' and then rerun the script. 

    If you see this error then you will need to disable the SELinux by setting it to permissive mode using the below command:

    sudo setenforce 0 

Still Not Working?

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.