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

André Pinto commented on LOG4J2-2804:
-------------------------------------

Is there anything specific about hours? I tested it with 45 seconds (so lower 
than the smallest time unit window in the file name pattern) and 10MB and got 
the same bug with erroneous file names:


{code:java}
-rw-r--r--  1 andre.pinto  staff    10M May  5 18:38 
main-2020-05-05-18.39.15-1.log
-rw-r--r--  1 andre.pinto  staff   7.7M May  5 18:39 
main-2020-05-05-18.39.15-2.log
-rw-r--r--  1 andre.pinto  staff    10M May  5 18:39 
main-2020-05-05-18.40.00-1.log
-rw-r--r--  1 andre.pinto  staff   7.8M May  5 18:40 
main-2020-05-05-18.40.00-2.log
-rw-r--r--  1 andre.pinto  staff    10M May  5 18:40 
main-2020-05-05-18.40.45-1.log
-rw-r--r--  1 andre.pinto  staff   7.8M May  5 18:40 
main-2020-05-05-18.40.45-2.log
-rw-r--r--  1 andre.pinto  staff    10M May  5 18:41 
main-2020-05-05-18.41.30-1.log
-rw-r--r--  1 andre.pinto  staff   7.4M May  5 18:41 
main-2020-05-05-18.41.30-2.log
-rw-r--r--  1 andre.pinto  staff   2.4M May  5 18:41 main-current.log-active
{code}

config:
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" name="Mux">

    <Properties>
        <Property name="LOG_DIR">logs</Property>
    </Properties>

    <Appenders>
        <Console name="Console" target="SYSTEM_OUT"/>

        <RollingRandomAccessFile name="main" 
fileName="${LOG_DIR}/main-current.log-active"
                                 
filePattern="${LOG_DIR}/main-%d{yyyy-MM-dd-HH.mm.ss}-%i.log"
                                 ignoreExceptions="false" immediateFlush="false"
                                 bufferSize="1048576">
            <PatternLayout>
                <Pattern>%m\n</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="10 MB" />
                <TimeBasedTriggeringPolicy interval="45" />
            </Policies>
            <DefaultRolloverStrategy fileIndex="nomax" />
        </RollingRandomAccessFile>

    </Appenders>
    <Loggers>
        <Root level="OFF">
            <AppenderRef ref="Console" />
        </Root>
        <Logger name="main" level="ALL" additivity="false">
            <AppenderRef ref="main"/>
        </Logger>
    </Loggers>
</Configuration>

{code}

It clearly seems that Log4j's rollovers don't properly support proper file 
naming with multiple triggers.

> RollingRandomAccessFile uses wrong time for filename
> ----------------------------------------------------
>
>                 Key: LOG4J2-2804
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2804
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.13.1
>            Reporter: André Pinto
>            Priority: Major
>
> When there are both size based and time based triggering policies, if the 
> size based policy is triggered, the file is named as if the time based policy 
> was triggered.
> Example config:
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN" name="Mux">
>     <Properties>
>         <Property name="LOG_DIR">logs</Property>
>     </Properties>
>     <Appenders>
>         <Console name="Console" target="SYSTEM_OUT"/>
>         <RollingRandomAccessFile name="main" 
> fileName="${LOG_DIR}/main-current.log-active"
>                                  
> filePattern="${LOG_DIR}/main-%d{yyyy-MM-dd-HH.mm.ss}.log"
>                                  ignoreExceptions="false" 
> immediateFlush="false"
>                                  bufferSize="1048576">
>             <PatternLayout>
>                 <Pattern>%m\n</Pattern>
>             </PatternLayout>
>             <Policies>
>                 <SizeBasedTriggeringPolicy size="256 B" />
>                 <TimeBasedTriggeringPolicy interval="3600" />
>             </Policies>
>             <DefaultRolloverStrategy fileIndex="nomax" />
>         </RollingRandomAccessFile>
>     </Appenders>
>     <Loggers>
>         <Root level="OFF">
>             <AppenderRef ref="Console" />
>         </Root>
>         <Logger name="main" level="ALL" additivity="false">
>             <AppenderRef ref="main"/>
>         </Logger>
>     </Loggers>
> </Configuration>
> {code}
> With this configuration if I start writing log entries to the "main" logger 
> at 2020-03-09 13:00.00 and immediately trigger the SizeBasedTriggeringPolicy 
> (256 bytes), the name of the file that is rolled over will be:
> main-2020-03-09-14.00.00
> as if the rollover operation had been triggered by the time policy.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to