Creating Multiple Log Files of Varying Content with Log4j
Question: It is possible to configure log4j to output different logging levels to separate appenders?
The goal is to establish multiple log files where a primary log captures INFO-level messages and higher from all classes, while a secondary log exclusively captures DEBUG-level messages from a specific group of classes.
Answer:
Log4j can be configured to accomplish the desired logging behavior:
<code class="xml"># Define the root logger log4j.rootLogger=QuietAppender, LoudAppender, TRACE # Configure Appender A (QuietAppender) for INFO and higher messages log4j.appender.QuietAppender=org.apache.log4j.RollingFileAppender log4j.appender.QuietAppender.Threshold=INFO log4j.appender.QuietAppender.File=quiet.log # Configure Appender B (LoudAppender) for DEBUG and higher messages log4j.appender.LoudAppender=org.apache.log4j.RollingFileAppender log4j.appender.LoudAppender.Threshold=DEBUG log4j.appender.LoudAppender.File=loud.log # Set the logging level to TRACE for a specific class or package log4j.logger.com.yourpackage.yourclazz=TRACE</code>
The above is the detailed content of How to Configure Log4j to Output Different Logging Levels to Separate Appenders?. For more information, please follow other related articles on the PHP Chinese website!