Apache Tomcat

How Do I View Tomcat Logs in Windows?

Apache Tomcat is one of the most popular web servers for Java applications. Like most web servers, Apache Tomcat allows you to configure logging settings for the main web server and the java applications.

Using apache logs, you can monitor how the server and your applications are running. Tomcat uses a customized implementation of the JULI (Java Utility Logging Implementation) provided in the java.util.logging package.

The purpose of this quick tutorial is to show you how to set up and view the Apache Tomcat logs on a Windows system.

Apache Tomcat Logs Location in Windows

By default, Apache Tomcat logs are stored in the install_dir/logs where the install_dir refers to the Apache Tomcat installation directory.

For example, the default install_dir for Apache Tomcat 10 is:

C:\Program Files\Apache Software Foundation\Tomcat 10.0

The log files are stored in the logs directory.

Types of Apache Tomcat Log Files

Depending on the Log level set for the Apache Tomcat server, you will find the following log files inside the log directory:

catalina.log
localhost.log
localhost_access_log

Catalina Log

The Catalina log file contains the comprehensive Apache Tomcat logs. It includes log information such as the startup and shutdown of the Tomcat server, fail records for various subsystems, and even the deployment of applications on the server.

Each message in the catalina.log file takes the format of the date and time of the event, the debug level, the log source, the class responsible for the event, and the command.

It is good not to modify the values in the log file as it might tamper with the time of the log and provide incorrect information to log analyzers.

An example catalina.log contents are as shown:

Some log information in the catalina.log file includes uncaught exceptions in the java.lang.ThreadGroup.uncaughtException and thread dumps requested by system signal.

Localhost Log

The localhost log is another default log file in the logs directory of the Apache Tomcat used to store the HTTP transactions between the client and the Apache tomcat server. In Windows, the log file has a .log extension, and you’ll find it in the same directory as the catalina.log file.

Access Log

The access log has a similar name as the localhost log but adds the access in the filename. It contains all log information of the HTTP requests to the server.

Entries in the access log take the format of source address, date and time of access, HTTP method, resource requested (static files such as images, CSS, html, js, and more), status code, HTTP header, and the PID.

An example output of this file is below:

Apache Tomcat Log Format

Apache Tomcat uses a standardized format for its logging entries, which is helpful for readability across Tomcat versions and devices. Additionally, you can use grep, sed, and AWK tools to parse the log files’ entries.

The files that follow Apache Tomcat logging standard format are catalina.log, localhost.log, and access.log.

The first section of the log entry starts with the timestamp. The timestamp is locale-formatted and contains both the date and time for that specific log entry.

The other portion of the log file contains the data, which may vary depending on the log type.

NOTE: Apache Tomcat does not handle logging for applications deployed to the server. Each application should implement a logging format.

The syntax for the catalina.log file is:

TIMESTAMP (date & time) [SEVERITY] [SUBSYSTEM] [LOG MESSAGE]

TIMESTAMP – As mentioned, the time stamp contains the time and date for the specific log entry. This information is queried from the operating system for accurate locale time zone and format.

SEVERITY – This field dictates the log level of the log entry. The log levels include INFO, WARN, FATAL, ERROR, TRACE, or DEBUG.

SUBSYSTEM – Refers to the tomcat subsystem or the module for the specific log entry.

LOG MESSAGE – The actual log entry.

In Windows, you can change the Apache Tomcat log files using the configuration manager. Click on start and search “Configure Tomcat.”

Navigate to the Logging Tab and select your logging level.

NOTE: You may need to restart Apache Tomcat to apply the logging levels.

Conclusion

This tutorial showed you how to view and work with Apache Tomcat logs in the Windows system. To learn more, check the Apache Tomcat logging documentation.

Thank you for reading!

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