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

See Apache: Tips and Tricks for similar articles.

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, logging.properties. 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/logging.properties (e.g., /var/lib/tomcat7/conf/logging.properties) for edit. Locate the following two lines:
    1catalina.org.apache.juli.AsyncFileHandler.level = INFO  
    1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs	
    	
  4. Change the directory name to /logExercise as shown below:
    1catalina.org.apache.juli.AsyncFileHandler.level = INFO
    1catalina.org.apache.juli.AsyncFileHandler.directory = /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.

Related Articles

  1. How to Start and Stop Apache Tomcat from the Command Line (Windows)
  2. How to Deploy a WAR File to Apache Tomcat (Windows)
  3. How to Start and Stop Apache Tomcat from the Command Line (Linux)
  4. How to Deploy a WAR File to Apache Tomcat (Linux)
  5. How to Run a JSP Program in Apache Tomcat (Windows)
  6. How to Check the Status of the Apache Tomcat Server (Windows)
  7. How to Deploy a Web Application Using the Apache Tomcat Manager (Windows)
  8. How to Check the Status of the Apache Tomcat Server (Linux)
  9. How to Set Default Context Path in Apache Tomcat (Windows)
  10. How to Use the autoDeploy Attribute in Apache Tomcat (Windows)
  11. How to Deploy a Web Application Using the Apache Tomcat Manager (Linux)
  12. How to List Deployed Applications Using the Apache Tomcat Manager (Windows)
  13. How to Run Multiple Instances of Apache Tomcat on One Server (Windows)
  14. How to Run a JSP Program in Apache Tomcat (Linux)
  15. How to Establish a JDBC Connection in Apache Tomcat (Windows)
  16. How to Verify Apache Tomcat Server Operation (Windows)
  17. How to Cluster in Apache Tomcat (Linux)
  18. How to Undeploy Web Applications Using the Apache Tomcat Manager (Windows)
  19. How to Set Default Context Path in Apache Tomcat (Linux)
  20. How to Use the Java Logging API in Apache Tomcat (Windows)
  21. How to Cluster in Apache Tomcat (Windows)
  22. How to Use the Java Logging API in Apache Tomcat (Linux) (this article)
  23. How to Use the autoDeploy Attribute in Apache Tomcat (Linux)
  24. How to Configure Apache Tomcat to Use MBeans (Windows)
  25. How to List Deployed Applications Using the Apache Tomcat Manager (Linux)
  26. How to Install and Configure Apache Tomcat (Windows)
  27. How to Configure Apache Tomcat to Use MBeans (Linux)