如何解决除指定记录器外的所有记录器的记录器配置
我有以下演示代码:
package playground;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Practice {
private static Logger log = LogManager.getLogger();
public static void main(String[] args) {
log.debug("Hello,world!");
}
}
我希望所有从包'playground'记录的日志都从'debug'级别向上记录到file1.log,并且所有其他记录器仅在出错或以上时才记录到file2.log。我尝试了以下配置:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<Appenders>
<RollingFile name="File1"
fileName="file1.log"
filePattern="file1-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="1 MB"/>
</Policies>
<DefaultRolloverStrategy max="15"/>
</RollingFile>
<RollingFile name="File2"
fileName="file2.log"
filePattern="file2-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="1 MB"/>
</Policies>
<DefaultRolloverStrategy max="15"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="playground" level="debug">
<AppenderRef ref="File1"/>
</Logger>
<Root level="error">
<AppenderRef ref="File2"/>
</Root>
</Loggers>
</Configuration>
但是,我发现自己的“世界你好!”日志消息同时发送到file1.log和file2.log。如何使我的“操场”记录器仅 进入file1?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。