log4j 2 - 配置问题 [英] log4j 2 - configuration issue
本文介绍了log4j 2 - 配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试配置log4j 2.0来报告日志。
I am trying to configure log4j 2.0 to report logs.
我的配置保存为log4j2.xml,这是它的内容:
My config is saved as log4j2.xml and this is its content:
<?xml version="1.0" encoding="UTF-8"?>
<configuration name="PRODUCTION" status="OFF">
<appenders>
<RollingFile name="MyFileAppender"
fileName="../Logs/app.log"
filePattern="../Logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="trace">
<appender-ref ref="MyFileAppender"/>
</root>
</loggers>
</configuration>
它存在于项目的类路径中,我尝试将其放在许多其他目录中..
It exists in the classpath of the project and I tried putting it in many other directories..
我在代码中创建了一个记录器,如下所示:
I created a logger in the code like so:
Logger logger = LogManager.getLogger(MyClass.class.getName());
logger.info("test");
没有写任何内容,也没有创建文件。
当我调试代码时,我看到记录器是默认的记录器(控制台)。
And nothing is written and no file is created. When I debug the code I see that the logger is the default logger(console).
推荐答案
好的,我解决了这个问题。
我必须在xml中指定package =myPackage
Ok, I solved the problem. I had to specify in the xml the package="myPackage"
这篇关于log4j 2 - 配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文