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

Unable to prevent file renames during rollovers

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Configuration
    • None

    Description

      We have an app that's using log4j2 for logging. The file that we want to be logging to is 

      access.log
      

      The current log4j2 config causes it to rename access.log to access.log.2022-01-30-30 (for example) then recreate the access.log file. This can cause data loss problems for log forwarding tools that expect to tail the same log file without having it change out from underneath them.

      I have tried playing around with the `DirectWriteRolloverStrategy` attribute, but by using that, I lose the ability to start with a specified `fileName`, because this policy doesn't support the `fileName` parameter. Hence, we'd lose the ability to log to `access.log`. 
      Is there a way around this? 

      Desired behavior:

      Current logging always goes to `access.log`.

      The files rollover based on the strategy specified in my log4j2 config file.

      Renames do not happen for the current file.

      Here's my current config file:

      <?xml version='1.0' encoding='utf-8'?>
      <Configuration>
          <Appenders>
              <Console name="stdout" target="SYSTEM_OUT">
                  <PatternLayout pattern="%m%n" />
              </Console>
              <RollingFile name="traffic_router_access"
                           fileName="access.log"
                           filePattern="access.log.%i" >
                  <PatternLayout pattern="%m%n" />
                  <Policies>
                      <SizeBasedTriggeringPolicy size="10KB"/>
                  </Policies>
                  <DirectWriteRolloverStrategy maxFiles="10"/>
                  <ThresholdFilter level="INFO" />
              </RollingFile>
          </Appenders>
          <Loggers>
              <Logger name="org.apache.traffic_control.traffic_router.core.access" level="INFO" additivity="false" >
                  <AppenderRef ref="traffic_router_access" />
              </Logger>
              <Root level="WARN" additivity="false" >
                  <AppenderRef ref="stdout" />
              </Root>
          </Loggers>
      </Configuration> 

      Attachments

        Activity

          People

            Unassigned Unassigned
            srijeet0406 Srijeet Chatterjee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: