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

NullPointerException using fileName property of RollingFile Appender with DirectWriteRolloverStrategy

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.8.1
    • Fix Version/s: 2.9.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Windows 7 64-bit JDK 8

      Description

      When using a RollingFileAppender with a DirectWriteRolloverStrategy if the fileName property of the appender is set, rollover fails with a NullPointerException. If the fileName attribute is not present logging works as intended.

      Configuration that produces this error:

      log4j2.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="warn" name="MyApp" packages="">
          <Properties>
              <Property name="baseDir">C:/logs</Property>
          </Properties>
          <Appenders>
              <RollingFile name="RollingFile" fileName="${baseDir}/app.log"
                           filePattern="${baseDir}/app-%d{yyyy-MM-dd'T'HH_mm_ss}.log">
                  <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
                  <TimeBasedTriggeringPolicy interval="10"/>
                  <DirectWriteRolloverStrategy>
                      <Delete basePath="${baseDir}">
                          <IfFileName glob="app-*.log" />
                          <IfAccumulatedFileCount exceeds="10" />
                      </Delete>
                  </DirectWriteRolloverStrategy>
              </RollingFile>
          </Appenders>
          <Loggers>
              <Root level="trace">
                  <AppenderRef ref="RollingFile"/>
              </Root>
          </Loggers>
      </Configuration>
      

      Stack Trace:

      2017-03-02 13:38:52,023 main ERROR An exception occurred processing Appender RollingFile java.lang.NullPointerException: activeFileName
      	at java.util.Objects.requireNonNull(Objects.java:228)
      	at org.apache.logging.log4j.core.appender.rolling.RolloverDescriptionImpl.<init>(RolloverDescriptionImpl.java:60)
      	at org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy.rollover(DirectWriteRolloverStrategy.java:194)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:362)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(RollingFileManager.java:278)
      	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:218)
      	at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:267)
      	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:448)
      	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:433)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
      	at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:439)
      	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:434)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:403)
      	at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
      	at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1993)
      	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1852)
      	at org.apache.logging.slf4j.Log4jLogger.error(Log4jLogger.java:299)
      

        Attachments

          Activity

            People

            • Assignee:
              ralph.goers@dslextreme.com Ralph Goers
              Reporter:
              AHuck Austin Huck
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: