[ 
https://issues.apache.org/jira/browse/LOG4J2-1978?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Russ updated LOG4J2-1978:
-------------------------
    Description: 
Rolled dated log files have the wrong date, in relation to the enclosed dated 
log entries.

Rolled dated log file should mirror the date of the enclosed log entries.

Using the following example of a "daily rolling file" ... 
* FilePattern: App_%d{yyyy-MM-dd}.log
* log entries for the date: (ie.) 2017-12-01 (note: the day is the 1st)
* are logged in base file named: (ie.) App_2017-12-01.log (note: the day is the 
1st)
* The first occurrence of the roll should be midnight on the 2nd but that does 
NOT occur
* Log file App_2017-12-01.log now contains log entries for both 2017-12-01 and 
2017-12-02
* The second occurrence of the roll is on the 3rd, and does occur, however...
* Log file App_2017-12-02.log is now having log entries for 2017-12-03 written 
to it

This occurs similarly at any level of granularity, of the date/time iteration. 
For instance.. 
* with a FilePattern (focusing on the date pattern specifically) of: 
%d{yyyy-MM-dd_HH-mm}
* log entries for: 2017-12-01_08-32
* will be in the rolled file: 2017-12-01_08-31

Example log4j2.xml property file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" monitorInterval="30">
  <Properties>
    <Property name="FilePattern">App_%d{yyyy-MM-dd}.log</Property>
    <Property name="PatternLayout">%x%X 
[%d{DEFAULT}][%-20t]%-5p(%-40.40C{3}:%-3L) - %m%n</Property>
  </Properties>

  <Appenders>
    <Console name="console-log" target="SYSTEM_OUT">
      <PatternLayout pattern="${PatternLayout}"/>
    </Console>

    <!-- either of the following 2 variations in declaration of the RollingFile 
have the same issue -->
    <!-- RollingFile name="file-log" fileName="base.log" 
filePattern="${FilePattern}" -->

    <RollingFile name="file-log" filePattern="${FilePattern}" bufferedIO="true" 
immediateFlush="true">
      <PatternLayout pattern="${PatternLayout}"/>
      <Policies>
        <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
      </Policies>
      <DirectWriteRolloverStrategy maxFiles="10"/> <!-- maxFiles attribute does 
not appear to work - older files are not being deleted -->
    </RollingFile>
  </Appenders>

  <Loggers>
    <Root level="all">
      <AppenderRef ref="console-log"/>
      <AppenderRef ref="file-log"/>
    </Root>
  </Loggers>
</Configuration>

  was:
Rolled dated log files have the wrong date, in relation to the enclosed dated 
log entries.

Rolled dated log file should mirror the date of the enclosed log entries.

Using the following example of a "daily rolling file" ... 
* FilePattern: App_%d{yyyy-MM-dd}.log
* log entries for the date: (ie.) 2017-12-01 (note: the day is the 1st)
* are logged in base file named: (ie.) App_2017-12-01.log (note: the day is the 
1st)
* When rolled at midnight .. (now) 2017/12/02 (note: the day is now the 2nd)
* Log entries of 2017-12-01 are now stored in a file name App_2017-12-02.log 
(note: the day on the file is the 2nd)

This occurs similarly at any level of granularity, of the date/time iteration. 
For instance.. 
* with a FilePattern (focusing on the date pattern specifically) of: 
%d{yyyy-MM-dd_HH-mm}
* log entries for: 2017-12-01_08-30
* will be in the rolled file: 2017-12-01_08-31

Additionally, this flaw affects the first roll over iteration, where the first 
iteration doesn't roll (on the first midnight), but does roll on subsequent 
iterations. For instance..
* with a FilePattern (focusing on the date pattern specifically) of: 
%d{yyyy-MM-dd}
* log entries for: 2017-12-01 (the app start date)
* the roll does not occur at midnight.. which is now: 2017-12-02

This results in the log file dated for the 1st, having entries for both the 1st 
and 2nd
* then on the 3rd, the log rolls, resulting in a rolled log dated: 2017-12-03, 
containing entries for both the 1st and 2nd
* Moving forward .. entries for the 3rd will be rolled into a log dated 
2017-12-04 .. so on and so forth

Example log4j2.xml property file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" monitorInterval="30">
  <Properties>
    <Property name="FilePattern">App_%d{yyyy-MM-dd}.log</Property>
    <Property name="PatternLayout">%x%X 
[%d{DEFAULT}][%-20t]%-5p(%-40.40C{3}:%-3L) - %m%n</Property>
  </Properties>

  <Appenders>
    <Console name="console-log" target="SYSTEM_OUT">
      <PatternLayout pattern="${PatternLayout}"/>
    </Console>

    <!-- either of the following 2 variations in declaration of the RollingFile 
have the same issue -->
    <!-- RollingFile name="file-log" fileName="base.log" 
filePattern="${FilePattern}" -->

    <RollingFile name="file-log" filePattern="${FilePattern}" bufferedIO="true" 
immediateFlush="true">
      <PatternLayout pattern="${PatternLayout}"/>
      <Policies>
        <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
      </Policies>
      <DirectWriteRolloverStrategy maxFiles="10"/> <!-- maxFiles attribute does 
not appear to work - older files are not being deleted -->
    </RollingFile>
  </Appenders>

  <Loggers>
    <Root level="all">
      <AppenderRef ref="console-log"/>
      <AppenderRef ref="file-log"/>
    </Root>
  </Loggers>
</Configuration>

Also note:


> Dated rolling files are incorrectly labeled with the date/time segment of the 
> future iteration
> ----------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1978
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1978
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.8.2
>            Reporter: Russ
>
> Rolled dated log files have the wrong date, in relation to the enclosed dated 
> log entries.
> Rolled dated log file should mirror the date of the enclosed log entries.
> Using the following example of a "daily rolling file" ... 
> * FilePattern: App_%d{yyyy-MM-dd}.log
> * log entries for the date: (ie.) 2017-12-01 (note: the day is the 1st)
> * are logged in base file named: (ie.) App_2017-12-01.log (note: the day is 
> the 1st)
> * The first occurrence of the roll should be midnight on the 2nd but that 
> does NOT occur
> * Log file App_2017-12-01.log now contains log entries for both 2017-12-01 
> and 2017-12-02
> * The second occurrence of the roll is on the 3rd, and does occur, however...
> * Log file App_2017-12-02.log is now having log entries for 2017-12-03 
> written to it
> This occurs similarly at any level of granularity, of the date/time 
> iteration. For instance.. 
> * with a FilePattern (focusing on the date pattern specifically) of: 
> %d{yyyy-MM-dd_HH-mm}
> * log entries for: 2017-12-01_08-32
> * will be in the rolled file: 2017-12-01_08-31
> Example log4j2.xml property file:
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="trace" monitorInterval="30">
>   <Properties>
>     <Property name="FilePattern">App_%d{yyyy-MM-dd}.log</Property>
>     <Property name="PatternLayout">%x%X 
> [%d{DEFAULT}][%-20t]%-5p(%-40.40C{3}:%-3L) - %m%n</Property>
>   </Properties>
>   <Appenders>
>     <Console name="console-log" target="SYSTEM_OUT">
>       <PatternLayout pattern="${PatternLayout}"/>
>     </Console>
>     <!-- either of the following 2 variations in declaration of the 
> RollingFile have the same issue -->
>     <!-- RollingFile name="file-log" fileName="base.log" 
> filePattern="${FilePattern}" -->
>     <RollingFile name="file-log" filePattern="${FilePattern}" 
> bufferedIO="true" immediateFlush="true">
>       <PatternLayout pattern="${PatternLayout}"/>
>       <Policies>
>         <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
>       </Policies>
>       <DirectWriteRolloverStrategy maxFiles="10"/> <!-- maxFiles attribute 
> does not appear to work - older files are not being deleted -->
>     </RollingFile>
>   </Appenders>
>   <Loggers>
>     <Root level="all">
>       <AppenderRef ref="console-log"/>
>       <AppenderRef ref="file-log"/>
>     </Root>
>   </Loggers>
> </Configuration>



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to