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

Delete on Rollover must work for DirectWriteRolloverStrategy

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.11.1
    • None
    • None
    • None

    Description

      Delete on Rollover is limited to DefaultRolloverStrategy

      Why not to add the same feature to the DirectWriteRolloverStrategy  ?

       

      Edit :

      What i want :

      • For Each startup use a log file with the date in its name
      • For multiple startup the same day, append log in the same file
      • Keep only the last 10 log files

       

      If i use DefaultRolloverStrategy, i can keep the last 10 startup in separate file and use DeleteAction to limit the number of log file (for test i use 10, but in prod it's 100 = 10 days * 10 startup)

      => It's bad for me, because i can't have more than 10 startup per day logged.
      See the result in ScreenShot-132.png

      <RollingFile name="ROCOPYTRACE" filename = "${basePath}/robocopy.log" filePattern = "${basePath}/robocopy-%d{yyyyMMdd}-%i.log">
          <PatternLayout pattern="%msg%n"/>
          <Policies>
              <OnStartupTriggeringPolicy />
          </Policies>
          <DefaultRolloverStrategy max="10">
              <Delete basePath = "${basePath}">
                  <IfFileName glob="robocopy-*.log">
                      <IfAccumulatedFileCount exceeds="10"/>
                  </IfFileName>
              </Delete>
          </DefaultRolloverStrategy>
      </RollingFile>

       

      If i use DirectWriteRolloverStrategy i can have 1 file per day.
      But DeleteAction is never run and i have too many file
      See the result in ScreenShot-133.png

       

      <RollingFile name="ROCOPYTRACE" filePattern = "${basePath}/robocopy-%d{yyyyMMdd}.log">
          <PatternLayout pattern="%msg%n"/>
          <Policies>
              <OnStartupTriggeringPolicy />
          </Policies>
          <DirectWriteRolloverStrategy>
              <Delete basePath = "${basePath}">
                  <IfFileName glob="robocopy-*.log">
                      <IfAccumulatedFileCount exceeds="10"/>
                  </IfFileName>
              </Delete>
          </DirectWriteRolloverStrategy>
      </RollingFile>

       

      Il i useTimeBasedTriggeringPolicy or CronTriggeringPolicy and DefaultRolloverStrategy then a run can be split into 2 file.

       

      Attachments

        1. ScreenShot-132.png
          6 kB
          lionel sauron
        2. ScreenShot-133.png
          7 kB
          lionel sauron

        Activity

          People

            Unassigned Unassigned
            altair2010 lionel sauron
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: