英文:
Log4j2 - Date is not working in new format
问题
最近我升级了log4j,这使得我在XML级别上进行了更改,我按照以下方式进行了更改。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<!-- 用于控制台的 appender -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %m%n%ex"/>
</Console>
</Appenders>
<Loggers>
<Root level="fatal">
<AppenderRef ref="console"/>
</Root>
</Loggers>
</Configuration>
但在更改为log4j2格式后,数据未按预期打印,例如 "2019-07-26 17:53:28,261",而显示为 "%d"。
%d DEBUG [main] new Test
%d DEBUG [main] new Test1
%d DEBUG [main] new Test2
我是否遗漏了某些配置?
英文:
Recently I have upgraded the log4j which made me change in XML level
And I did as below.
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="warn">
<Appenders>
<!-- An appender for the console -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %m%n%ex"/>
</Console>
</Appenders>
<Loggers>
<Root level="fatal">
<AppenderRef ref="console"/>
</Root>
</Loggers>
</Configuration>
But after changing format as log4j2, the Data is not printing as expected like "2019-07-26 17:53:28,261" instead it displays as "%d".
%d DEBUG [main] new Test
%d DEBUG [main] new Test1
%d DEBUG [main] new Test2
Am I missing any configuration?
答案1
得分: 0
发现了问题。实际问题是 Log4j2.xml(src/main/resources/log4j2.xml)中的更改未在生成的文件(target/classes/log4j2.xml)中得到体现,其中日期的模式是错误的 "%%d"。
英文:
Found the Issue. The actual problem is the changes in Log4j2.xml (src/main/resources/log4j2.xml) is not get reflected in the Generated file (target/classes/log4j2.xml) in which the Pattern of date is wrong "%%d".
专注分享java语言的经验与见解,让所有开发者获益!
评论