时间戳错误的 Log4j 2 滚动文件

我有以下 Roling 文件:


<RollingFile name="mylog"

                 filePattern="${sys:server.output.dir}/logs/mylog_%d{yyyy-MM-dd}.%i.log"

                 ignoreExceptions="false">

        <PatternLayout>

            <Pattern>%d %-5p %c %m%n\n</Pattern>

        </PatternLayout>

        <Policies>

            <OnStartupTriggeringPolicy minSize="100000000" />

            <SizeBasedTriggeringPolicy size="100 MB" />

            <TimeBasedTriggeringPolicy />

        </Policies>

        <DirectWriteRolloverStrategy />

    </RollingFile>

但是我得到了错误的时间戳。


如果日志是在6 月 24 日创建的,则它被称为mylog_2019-06-23.1.log,它包含24 日的文件。


最后生成的文件是为了更好地说明:


mylog_2019-06-20.1.log  - generated on 21st at 23:50 - contains logs from 21st


mylog_2019-06-21.1.log  - 22nd at 23:50 - contains logs from whole 22nd


mylog_2019-06-22.1.log  - 23rd at 00:00 - contains logs from 23rd to 7 AM


mylog_2019-06-23.1.log  - 23rd at 23:50 - contains logs from 23rd 7 AM to end of day


mylog_2019-06-23.2.log  - 24th at 00:00 - contains logs from today (24th) until now

我究竟做错了什么?(任何间隔都会发生同样的情况,例如分钟 - 邮票总是关闭一个单位)


慕妹3242003
浏览 116回答 1
1回答

冉冉说

所以最后我不得不将 fileName 属性添加到 RollingFile 元素并将策略更改为并且它现在可以工作了。Nomax 只是不限制要保留的文件数量。副作用是现在日志首先记录到 mylog.log 中,当文件翻转时,它被重命名为 mylog_{stamp}.log。<RollingFile name="myLog"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fileName="${sys:server.output.dir}/logs/mylog.log"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filePattern="${sys:server.output.dir}/logs/mylog_%d{yyyy-MM-dd}.%i.log"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ignoreExceptions="false">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <PatternLayout>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Pattern>%d %-5p %c %m%n\n</Pattern>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </PatternLayout>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Policies>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <OnStartupTriggeringPolicy/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <SizeBasedTriggeringPolicy size="100 MB" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TimeBasedTriggeringPolicy/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Policies>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <DefaultRolloverStrategy fileIndex="nomax"/>&nbsp; &nbsp; &nbsp; &nbsp; </RollingFile>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java