log4j2:pattern不包含日期

时间:2014-08-28 17:59:01

标签: java eclipse log4j2

我尝试迁移到log4j2并且我收到了java.lang.IllegalStateException:" Pattern不包含日期。"

我为每个RollingFile设置了一个filePattern,所以我不确定我做错了什么。仅供参考,我在Eclipse(Kepler)上运行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>

2 个答案:

答案 0 :(得分:1)

TimeBasedTriggeringPolicy需要日期来确定文件翻转的频率

答案 1 :(得分:0)

这个问题似乎已经解决了。我将log4j2.xml移到Eclipse的src目录的顶部,这就是诀窍。