How to configure logging in Tomcat

Home > Search > How-to
  by

Catalina / Localhost / Manager logs

The ${catalina.base}/conf/logging.properties file controls how Tomcat handles logging globally. Following is an excerpt of a logging.properties file. This file specifies the directory where log files will reside, and the log file prefix, such as catalina, localhost, and manager.

By default, the log level is set to FINE. The log levels that can be used are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST or ALL.

1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.

2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.

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.bufferSize = 16384

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

access logs

The $CATALINA_HOME/conf/server.xml file controls how events are written to the access log. By default, the server.xml file should have something similar to the following.

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

 

The above will create log files in the $CATALINA_HOME/logs/ directory. The log files will be named localhost_access_log.date.txt.

Let's use a scenario where the Tomcat server has IP address 10.0.0.1 and a client with IP address 10.0.0.2 navigates to http://tomcat_hostname:8080 to get the Tomcat web interface. This will write the following events in the access log. The access log contains the IP address of the remote machine, the date and time a request was requested, the resource that was requested, and the status code.

10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET / HTTP/1.1" 200 11256
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /tomcat.css HTTP/1.1" 200 5581
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /tomcat.png HTTP/1.1" 304 -
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /bg-nav.png HTTP/1.1" 304 -
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /asf-logo-wide.svg HTTP/1.1" 304 -
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /bg-upper.png HTTP/1.1" 304 -
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /bg-middle.png HTTP/1.1" 304 -
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /bg-button.png HTTP/1.1" 304 -
10.0.0.2 - - [07/Jul/2017:10:07:47 -0500] "GET /favicon.ico HTTP/1.1" 200 21630

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments