简体   繁体   English

log4j 2 RollingFileAppender删除日志内容

[英]log4j 2 RollingFileAppender deleting content of log

The following configuration is supposed to create a new log file everyday: 以下配置应该每天创建一个新的日志文件:

<configuration status="trace">
  <appenders>

    <RollingFile name="RollingFile" fileName="../logs/excepciones.log" filePattern="../logs/excepciones.log.%d{yyyy-MM-dd}">
     <PatternLayout>
       <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
     </PatternLayout>
     <Policies>
       <TimeBasedTriggeringPolicy interval="1" modulate="true" />
     </Policies>
   </RollingFile>
 </appenders>
 <loggers>

   <root level="error">
    <appender-ref ref="RollingFile"/>
   </root>
   <root level="info">
     <appender-ref ref="RollingFile"/>
   </root>
 </loggers>
</configuration>

I do get a new file every day in the form excepciones.log-yyyy-MM-dd , the problem is that this new file contains only the last line that was inserted to excepciones.log before it was rolled to excepciones.log-yyyy-MM-dd , but I can't seem to figure out why. 我每天都会以excepciones.log-yyyy-MM-dd的形式获取一个新文件,问题是该新文件仅包含插入到excepciones.log的最后一行,然后才将其滚动到excepciones.log-yyyy-MM-dd ,但我似乎无法弄清楚原因。 What I want is the whole content of today's log to be copied into a new file at 12:00 am. 我想要的是将今天日志的全部内容在上午12:00复制到一个新文件中。

So for example, yesterday, my log's content was: 例如,昨天,我的日志内容为:

this is line 1
this is line 2
this is line 3

Today, that file has been renamed to `excepciones.log-2014-07-07, but its content is now: 今天,该文件已重命名为`excepciones.log-2014-07-07,但其内容现在为:

this is line 1

What version of log4j2 are you using? 您正在使用哪个版本的log4j2? Your problem description reminds me of LOG4J2-531 which was fixed in log4j2-rc1. 您的问题描述让我想起了LOG4J2-531其固定在log4j2-RC1。

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

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