Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-907

Log4j2 rolling policy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.1
    • 2.8
    • Appenders
    • None
    • windows 7 enterprise

    Description

      I am using log4j2 and a rolling file appender, to roll file based on size and time. See my attached config file config file and the following snippet:

       <RollingFile name="RollingFile" filename="log/$${date:dd-MM-yyyy-HH-mm}/currentRoll.log" filePattern="log/%d{dd-MM-yyyy-HH-mm}/Roll-%i.log">
                  <PatternLayout>
                      <Pattern>%d{ISO8601}{GMT} %p %c{1.c} [%t] %m%n</Pattern>
                  </PatternLayout>
      
                  <Policies>
                      <TimeBasedTriggeringPolicy interval="1"/>
                      <SizeBasedTriggeringPolicy size="3KB"/>
                  </Policies>
              </RollingFile>
      

      My problem is that my current log (currentRoll.log) file is in the folder that was first created when the program started. I would need it to be in the last. So for example if I start running the program at 1pm on November 25th, 2014 , and at 3pm I want to look at the current logs they would not be in the 25-11-2014-15 folder but in the 25-11-2014-13 folder.

      My guess is that the date in the filename is not resolved dynamically. I have tried using monitorInterval to poll for auto reconfiguration but did not have any luck. I also tried using a '$$' in

      filename="log/$${date:dd-MM-yyyy-HH-mm}/currentRoll.log" .
      

      but got the following error:

      ERROR Unable to create file log/${date:dd-MM-yyyy-HH-mm}/currentRoll.log java.io.IOException: The filename, directory name, or volume label syntax is incorrect
      

      Any suggestion?

      Attachments

        1. log4j2.xml
          1 kB
          Clement Caylux

        Issue Links

          Activity

            People

              rgoers Ralph Goers
              ccaylux Clement Caylux
              Votes:
              4 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: