How to Use the Java Logging API in Apache Tomcat (Linux)

Developers and administrators alike will refer to Apache Tomcat logs from time for diagnostic and performance data. Tomcat uses a customized implementation of java.util.logging called JULI (Java Utility Logging Implementation). JULI is very similar to standard Java SE logging, even supporting the same configuration file, In this topic, we'll explore a way to route the Catalina logs to a specific destination and then check out the log contents.

To learn how to use the Java Logging API in Apache Tomcat for Linux following these 8 steps:

  1. Stop your Tomcat server.
  2. Directly under the root of your file system create a folder named logExercise.
  3. Open CATALINA_BASE/conf/ (e.g., /var/lib/tomcat7/conf/ for edit. Locate the following two lines: = INFO = ${catalina.base}/logs	
  4. Change the directory name to /logExercise as shown below: = INFO = /logExercise  
    In addition, verify that the log level is INFO as shown above. If the log level happens to be different, change it to INFO.
  5. Save your changes.
  6. You may need to change ownership of the directory in order for Tomcat to write to the folder. In a terminal window submit the following command:
    sudo chown tomcat7 logExercise   	
    where "tomcat7" should be changed to the user under which Tomcat is running.
  7. Start your Tomcat server.
  8. In your text editor, open the file you see under /logExercise. Here is a portion of my log:
    Log file contents example
    Note that the log line output contains the date, time, log level and a message. Because of the log level of INFO, messages with a level of informational or more severe levels (e.g., WARNING) are displayed.The screen shot above shows a warning message displayed among the informational messages.
Author: Stephen Withrow

Stephen has over 30 years of experience in training, development, and consulting in a variety of technology areas including Python, Java, C, C++, XML, JavaScript, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen has a degree in Computer Science and Physics from Florida State University.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.