You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2019/05/12 05:09:00 UTC

[jira] [Commented] (LOG4J2-2602) Same file is overwritten on rollover which causes logs loss

    [ https://issues.apache.org/jira/browse/LOG4J2-2602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16838001#comment-16838001 ] 

Ralph Goers commented on LOG4J2-2602:
-------------------------------------

The documentation for size-based triggering policy says "The file pattern must contain a {{%i}} otherwise the target file will be overwritten on every rollover as the SizeBased Triggering Policy does not cause the timestamp value in the file name to change." This sentence was added in 2.11.2.  As I recall the problem is that when the size-based appender is combined with a time-based appender a trigger driven from the size-based appender should just increment the counter and not cause the time to change. Changing the time in that case screws up the time-based appender. 

It may be possible to preserve the behavior you want if it is detected that only the size-based appender is present. I will have to check into that. But simply reverting that change is out of the question as it was necessary to fix a bunch of bugs in the time-based appenders.

> Same file is overwritten on rollover which causes logs loss
> -----------------------------------------------------------
>
>                 Key: LOG4J2-2602
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2602
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.11.2
>            Reporter: Vitaliy MAtuzko
>            Priority: Major
>
> In our log4j configuration we use SizeBasedTriggeringPolicy and DefaultRolloverStrategy(max>1) :
> {code:xml}
>     <Appenders>
>         <RollingRandomAccessFile name="file" fileName="log/server.log"
>                                  filePattern="log/server-%d{yyyy-MM-dd'T'HH-mm-ss}.log.gz">
>             <PatternLayout>
>                 <pattern>%level{length=1} %date{MMdd-HHmm:ss,SSS} %logger{1.} %message %X
>                     [%thread]%n
>                 </pattern>
>             </PatternLayout>
>             <Policies>
>                 <OnStartupTriggeringPolicy/>
>                 <SizeBasedTriggeringPolicy size="10 MB"/>
>             </Policies>
>             <DefaultRolloverStrategy max="2000"/>
>         </RollingRandomAccessFile>
>     </Appenders>
> {code}
>  
> After upgrading to log4j-core 2.11.2 we have noticed that after rollover insttead of creating new files same file gets overwritten.
> Looks like the issue is that
> org.apache.logging.log4j.core.appender.rolling.*PatternProcessor*#formatFileName gives same filename for rollover, and the difference between *2.11.1* version is that field "prevFileTime" never reseted after first time*:*
> *2.11.2 org.apache.logging.log4j.core.appender.rolling.PatternProcessor#updateTime*
> {code:java}
> public void updateTime() {
>  if (nextFileTime != 0) {
>  prevFileTime = nextFileTime;
> }
>  }
> {code}
>  
> it was always reseted in 2.11.1
> *2.11.1 org.apache.logging.log4j.core.appender.rolling.PatternProcessor#updateTime*
> {code:java}
> public void updateTime() {
>  prevFileTime = nextFileTime;
> }
> {code}
>  
> so the same time(*prevFileTime*) will be always used to form the filename for rollover
> *org.apache.logging.log4j.core.appender.rolling.PatternProcessor#formatFileName(org.apache.logging.log4j.core.lookup.StrSubstitutor, java.lang.StringBuilder, boolean, java.lang.Object)*
> {code:java}
> final long time = useCurrentTime ? currentFileTime != 0 ? currentFileTime : System.currentTimeMillis() :
>  prevFileTime != 0 ? prevFileTime : System.currentTimeMillis();
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)