Log4j2覆盖过去的日志文件 [英] Log4j2 overwrites past day log file

查看:411
本文介绍了Log4j2覆盖过去的日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Log4j2 ver 2.3

I'm using Log4j2 ver 2.3

log4j2.xml看起来像:

log4j2.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
    <RollingFile name="RollingFile"
                 fileName="${sys:catalina.base}/logs/catalina.${date:yyyy-MM-dd}.log"
                 filePattern="${sys:catalina.base}/logs/catalina.%d{yyyy-MM-dd}.log">
        <PatternLayout pattern="[TID=%X{TId}] %d{MMM dd, yyyy HH:mm:ss,SSS} %c %M:%L %p: %m%n"/>
        <TimeBasedTriggeringPolicy modulate="true" />
    </RollingFile>
</Appenders>
<Loggers>
    <Root level="DEBUG" >
        <AppenderRef ref="RollingFile" />
    </Root>
</Loggers>
</Configuration>

所有工作正常,直到第二天前一天的日志被当天的某些日志覆盖。

All works fine until next day when log from a previous day is getting overwritten by some logs from current day.

示例:
catalina.2018-03-21.log昨天(3月21日)没事,但今天被2018-03的一些日志覆盖了 - 22当catalina.2018-03-22.log包含今天(3月22日)的剩余日志时

Example: catalina.2018-03-21.log yesterday (March 21st) was fine but today got overwritten by some logs from 2018-03-22 when catalina.2018-03-22.log contains rest of logs from today (March 22nd)

有什么想法吗?

推荐答案

Log4j 2.3有些陈旧,于2015-05-09发布,差不多3岁。所以尝试使用更新版本;版本2.11.0是截至2018-03-11发布的最新版本。

Log4j 2.3 is somewhat old, being released on 2015-05-09, almost 3 years old. So try using a updated version; version 2.11.0 is the latest as of now which was released on 2018-03-11.

更新:要继续使用Log4j 2.3,您可以妥协您的要求。其中一个选项可能是使用 fileName 属性的静态值。例如。 ... / catalina.log ... / catalina.current.log 等。

Update: To continue using Log4j 2.3, you can compromise your requirements. One of the options could be using static value for fileName attribute. E.g. .../catalina.log, .../catalina.current.log, etc.

这篇关于Log4j2覆盖过去的日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆