我想迁移到log4j2,我得到一个java.lang.IllegalStateException:“模式不包含日期。”log4j2:模式不包含日期
我有一个filePattern为每个RollingFile设置,所以我不确定我在做什么错。仅供参考,我在Eclipse上运行Tomcat(开普勒)。
这里是我的log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p] - %m%n" />
</Console>
<RollingFile name="RootFile" fileName="injunction.log" immediateFlush="false" append="false"
filePattern="injunction.log.%d{yyyy-MM-dd}">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p] - %m%n"/>
<Policies>
<!-- Roll over the file to the next day -->
<TimeBasedTriggeringPolicy />
</Policies>
<!-- Only keep up to 30 archived log files -->
<DefaultRolloverStrategy max="30"/>
</RollingFile>
<RollingFile name="DBFile" fileName="db.log" immediateFlush="false" append="false"
filePattern="db.log.%d{yyyy-MM-dd}">>
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%-5p] - %m%n"/>
<Policies>
<!-- Roll over the file to the next day -->
<TimeBasedTriggeringPolicy />
</Policies>
<!-- Only keep up to 30 archived log files -->
<DefaultRolloverStrategy max="30"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
<AppenderRef ref="RootFile" />
</Root>
<Logger name="DBLogger" level="debug" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="DBFile" />
</Logger>
</Loggers>
</Configuration>
这是我从阿帕奇找到有关TimeBasedTriggeringPolicy: “多久侧翻应该发生基于在日期模式最具体的时间单位。例如,用小时日期模式是最具体的项目,和每4小时增加4次翻转,默认值为1。 不应该默认为1天吗? – 2014-08-28 18:28:54
它基于您日期模式中反映的最小单位,在您的情况下为秒。如果这是您想要的,您需要将间隔设置为全天的秒数。 另外,我认为你需要添加DatePattern字段(它看起来像你试图通过FilePattern来做) – coffeeaddict 2014-08-28 18:45:54
因为Eclipse已经决定它不能再找到我的log4j2.xml文件,所以我必须暂停这个问题。 – 2014-08-28 19:51:36