Apache Tomcat

How Do I View Tomcat Logs in Linux?

Apache Tomcat is a popular and powerful web server for Java applications. The Apache Tomcat logs are an essential feature that allows sysadmins to view what is accessed and how the server handles the various resources.

Although you can implement logging for the Java applications written for Tomcat, getting the internal webserver logs can be instrumental in troubleshooting.

This article will look at the overview of the Apache Tomcat logging, where the log files are stored in Linux, and how to tune them in the main configuration file.

Where Are Apache Tomcat Logs Located?

The location of the Apache Tomcat log files will depend on how the Tomcat server is installed. For example, if you have the server installed via a package manager, the location of the log files is in /var/log/tomcat.

On the other hand, if you have the server installed as a binary in a custom location, the log files are located inside the tomcat/logs directory.

However, you can modify the location of the log files by editing the configuration file and setting the value for the $CATALINA_OUT variable.

Inside the logs directory, you will find various logs files as shown below:

Tomcat Main Log File

The main Apache Tomcat file is determined by the value of the $CATALINA_OUT variable. By default, this is set to logs/catalina.out.

It contains log information about the Apache tomcat server. To view its contents, you can use commands such as less:

less catalina.out

Here is an example output in the catalina.out file:

To change the default location of the log file, edit the startup.sh file and locate the entry:

CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out

Change its value to a custom location as:

CATALINA_OUT=/var/log/tomcat.log

Tomcat Access Logs

Tomcat also stores the HTTP access logs in the logs directory. This file takes the format of:

<prefix-name>.YYYY-MM-DD.<suffix>

The prefix and suffix values are predefined in the server.xml file. To view the default values, use the command:

cat ../conf/server.xml | grep prefix

By default, the access log file name is as:

localhost_access_log.2021-09-02.txt

Here is an example access log file:

Tomcat History File

Apache Tomcat also provides history files for all its log files, including the main and access log files. Tomcat creates a new log file every day while saving the previous day’s logs in a new file. The file name begins with a similar name as the original log file but ends with the date of the log.

Here is an example:

How to Disable Tomcat Logging

In some instances, you may want to disable Apache Tomcat logging. To do this, edit the logging.properties file inside the conf directory and comment the following entry:

handlers = 1catalina.org.apache.juli.AsyncFileHandler,

2localhost.org.apache.juli.AsyncFileHandler...

To disable access logging, open the server.xml file and remove the following block:

<Valve className="org.apache.catalina.valves.AccessLogValve"

 directory="logs"

               prefix="localhost_access_log" suffix=".txt"

               pattern="%h %l %u %t "%r" %s %b" />

Closing

In this quick tutorial, we discussed the Apache Tomcat logs and how you can view them. We also discussed how to disable Apache logging when you need to do so.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list