简体   繁体   English

log4j2:pattern不包含日期

[英]log4j2: pattern does not contain a date

I'm trying to migrate to log4j2 and I'm getting an java.lang.IllegalStateException: "Pattern does not contain a date." 我正在尝试迁移到log4j2,我得到一个java.lang.IllegalStateException:“Pattern不包含日期。”

I have a filePattern setup for each RollingFile so I'm unsure what I'm doing wrong. 我为每个RollingFile设置了一个filePattern,所以我不确定我做错了什么。 FYI, I'm running through Tomcat on Eclipse (Kepler). 仅供参考,我在Eclipse(Kepler)上运行Tomcat。

Here is my log4j2.xml: 这是我的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需要日期来确定文件翻转的频率

This problem appeared to fix itself. 这个问题似乎已经解决了。 I moved the log4j2.xml to the top of Eclipse's src directory and that did the trick. 我将log4j2.xml移到了Eclipse的src目录的顶部,这就是诀窍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM