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:
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:
Change its value to a custom location as:
Tomcat Access Logs
Tomcat also stores the HTTP access logs in the logs directory. This file takes the format of:
The prefix and suffix values are predefined in the server.xml file. To view the default values, use the command:
By default, the access log file name is as:
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:
2localhost.org.apache.juli.AsyncFileHandler...
To disable access logging, open the server.xml file and remove the following block:
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.