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

RollingRandomAccessFileAppender with DirectWriteRolloverStrategy can't create the first log file of different directory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.18.0, 2.17.2
    • None
    • None
    • None

    Description

      When you want split the log into different directories by period (day, hour, minute, etc.), and use
      RollingRandomAccessFileAppender with a DirectWrite rollover, the config should be:

      <RollingRandomAccessFile name="RollingFile"  filePattern="${baseDir}/%d{s}/%d{s}.log">
          <PatternLayout header= "${LOG_HEADER}">
              <Pattern>${LOG_PATTERN}</Pattern>
          </PatternLayout>
          <Policies>
              <TimeBasedTriggeringPolicy/>
          </Policies>
      </RollingRandomAccessFile>
      

       At that time when you create the first log of each directory, console shows;

      2022-07-31 03:17:44,009 main ERROR RollingRandomAccessFileManager target/rolling-random-direct-switch-director/%d{s}/%d{s}.log Failed to create file after rollover: java.io.FileNotFoundException: target/rolling-random-direct-switch-director/44/44.log (No such file or directory) java.io.FileNotFoundException: target/rolling-random-direct-switch-director/44/44.log (No such file or directory) 
      

      Apparently the directory has not been created when the file is creating

      Attachments

        Activity

          People

            Unassigned Unassigned
            dafengsu su pei tao
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: