Keywords: Tomcat | Logging Configuration | DEBUG Level | JULI | Java Util Logging
Abstract: This article provides an in-depth analysis of common DEBUG level configuration failures in Tomcat's logging system, explaining the working mechanism of Java Util Logging (JUL) in Tomcat environment. Through comparison of user configurations and actual requirements, it offers complete debugging log configuration solutions covering log level definitions, handler configurations, logger settings, and optimization recommendations for different scenarios.
Problem Background and Phenomenon Analysis
In Tomcat logging configuration practice, developers often encounter this dilemma: despite setting the log level to DEBUG in the logging.properties file, the console output still only displays INFO and WARN level messages. The root cause of this phenomenon lies in insufficient understanding of the Java Util Logging (JUL) framework and Tomcat's JULI extension.
Java Util Logging Level System Analysis
Java Util Logging defines a strict hierarchy of log levels, from highest to lowest: SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST. It is particularly important to note that the standard JUL framework does not include a DEBUG level, which is the source of many configuration problems.
In actual Tomcat logging configuration, the FINE level corresponds to what is commonly understood as debug information. The following code example shows correct level settings:
# Correct log level configuration
1catalina.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.level = FINE
java.util.logging.ConsoleHandler.level = FINE
Collaborative Working Mechanism of Handlers and Loggers
Tomcat's logging system adopts a layered architecture containing two core components: handlers and loggers. The handler's level setting determines the minimum log level that the handler can process, while the logger's level setting controls which log messages are generated and passed to handlers.
In the user-provided configuration example, although various handlers are set to DEBUG level, only specifically named loggers are explicitly configured to DEBUG level. For other loggers not explicitly configured, they still use the default INFO level, which is why the console only displays INFO and WARN messages.
Global Log Level Configuration Solution
To achieve comprehensive debug log output, global level configuration needs to be added to the logging.properties file:
# Set global default log level to FINE
.level = FINE
This configuration will cause all loggers to generate log messages at FINE level and above. However, this approach will produce massive log output and may significantly impact system performance, especially in production environments.
Fine-grained Log Configuration Strategy
For most practical application scenarios, a more refined configuration strategy is recommended, enabling debug logs only for specific packages or components:
# Enable debug logs for specific packages
org.apache.catalina.startup.ContextConfig.level = FINE
org.apache.catalina.startup.HostConfig.level = FINE
org.apache.catalina.session.ManagerBase.level = FINE
# For custom application packages
com.example.myapp.level = FINE
Tomcat JULI Extension Features
Tomcat enhances the standard Java Util Logging framework through JULI extensions, providing the following important features:
- ClassLoader Awareness: Supports independent log configurations based on different class loaders
- System Property Substitution: Supports using
${systemPropertyName}syntax in configuration files - Extended Handler Configuration: Supports prefix naming and custom properties
- Asynchronous Log Processing: Improves performance through
org.apache.juli.AsyncFileHandler
Configuration Verification and Debugging Techniques
After modifying log configuration, the following steps are recommended for verification:
- Restart Tomcat server to ensure configuration takes effect
- Check startup logs in the
catalina.outfile - Verify timestamps and content of log files
- Use specific URLs to trigger application logic and generate debug logs
Below is a complete, optimized logging.properties configuration example:
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
# Handler configuration
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
1catalina.org.apache.juli.FileHandler.maxDays = 30
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
# Specific logger configuration
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = FINE
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
# Application-specific configuration
com.example.myapp.level = FINE
Production Environment Best Practices
When deploying in production environments, the following optimization measures should be considered:
- Remove console handler to reduce duplicate log output
- Configure log file rotation and retention policies
- Set different log levels for different application components
- Use asynchronous file handlers to improve I/O performance
- Regularly monitor log file sizes and disk space
By deeply understanding how Tomcat's logging system works and correctly configuring it, developers can effectively use debug logs to diagnose and resolve application issues while maintaining system performance and stability.