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

Cryptic error message when misconfigured with File and RollingRandomAccessFile appenders targeting same file

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.0
    • Component/s: Configurators, Core
    • Labels:
      None

      Description

      When a configuration contains a FileAppender and a RollingRandomAccessFileAppender that target the same file, the below error occurs.

      Admittedly the configuration is wrong, but the error message is misleading or at least not helpful for users. Without intimate understanding of the Log4j internals (how FileManagers work) it is almost impossible to determine that the below error is caused by a misconfiguration, what the problem is and how to fix it.

      The configuration:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="WARN">
        <properties>
          <property name="pattern">%d{ISO8601} %r [%t] %-5level %logger{1.} - %msg%n</property>
        </properties>
        <Appenders>
          <Console name="CONSOLE" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${pattern}" />
          </Console>
          <File name="FILE" fileName="logs/app.log">
            <PatternLayout pattern="${pattern}" />
          </File>
          <RollingRandomAccessFile name="ROLLING"
                 fileName="logs/app.log"
                 filePattern="logs/%d{yyyyMMdd}/app-%i.log.gz">
            <PatternLayout pattern="${pattern}" />
            <Policies>
              <OnStartupTriggeringPolicy/>
              <SizeBasedTriggeringPolicy size="1 GB" />
              <TimeBasedTriggeringPolicy/>
            </Policies>
            <DefaultRolloverStrategy/>
          </RollingRandomAccessFile>
        </Appenders>
        <Loggers>
          <Root level="DEBUG">
            <AppenderRef ref="CONSOLE" level="WARN"/>
            <AppenderRef ref="FILE" />
          </Root>
        </Loggers>
      </Configuration>
      

      Gives this error:

      2017-05-11 15:52:55,959 main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender, element RollingRandomAccessFile. java.lang.ClassCastException: org.apache.logging.log4j.core.appender.FileManager cannot be cast to org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager
              at org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager.getRollingRandomAccessFileManager(RollingRandomAccessFileManager.java:87)
              at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender$Builder.build(RollingRandomAccessFileAppender.java:115)
              at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender$Builder.build(RollingRandomAccessFileAppender.java:52)
              at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
              at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
              at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
              at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
              at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
              at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
              at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:76)
              at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
              at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
              at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
              at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
              at org.apache.logging.log4j.jul.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:34)
              at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
              at org.apache.logging.log4j.jul.LogManager.getLogger(LogManager.java:89)
              at java.util.logging.LogManager.demandLogger(LogManager.java:551)
              at java.util.logging.Logger.demandLogger(Logger.java:455)
              at java.util.logging.Logger.getLogger(Logger.java:502)
              at com.lmax.disruptor.FatalExceptionHandler.<clinit>(FatalExceptionHandler.java:27)
              at com.lmax.disruptor.dsl.ExceptionHandlerWrapper.<init>(ExceptionHandlerWrapper.java:8)
              at com.lmax.disruptor.dsl.Disruptor.<init>(Disruptor.java:66)
              at com.lmax.disruptor.dsl.Disruptor.<init>(Disruptor.java:105)
              at org.apache.logging.log4j.core.async.AsyncLoggerDisruptor.start(AsyncLoggerDisruptor.java:92)
              at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:75)
              at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
              at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
              at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
              at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
              at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
              at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
              at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
              at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
              at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
              at com.company.project.Main.main(Main.java:1030)
      

        Activity

        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 03ca82a9760574b99a6cd85aa259f86995b91b95 in logging-log4j2's branch refs/heads/master from rpopma
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=03ca82a ]

        LOG4J2-1908 fix test that was broken by pulling up the narrow() method from OutputStreamManager to AbstractManager

        Show
        jira-bot ASF subversion and git services added a comment - Commit 03ca82a9760574b99a6cd85aa259f86995b91b95 in logging-log4j2's branch refs/heads/master from rpopma [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=03ca82a ] LOG4J2-1908 fix test that was broken by pulling up the narrow() method from OutputStreamManager to AbstractManager
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 04820b8a89d1a64f58ef97a584586204854300ca in logging-log4j2's branch refs/heads/master from rpopma
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=04820b8 ]

        LOG4J2-1908 pull up the narrow() method from OutputStreamManager to AbstractManager

        Show
        jira-bot ASF subversion and git services added a comment - Commit 04820b8a89d1a64f58ef97a584586204854300ca in logging-log4j2's branch refs/heads/master from rpopma [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=04820b8 ] LOG4J2-1908 pull up the narrow() method from OutputStreamManager to AbstractManager
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 9d049426a6fb2976fa39c4642146ae4959a08709 in logging-log4j2's branch refs/heads/master from rpopma
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=9d04942 ]

        LOG4J2-1908 added comment and more javadoc

        Show
        jira-bot ASF subversion and git services added a comment - Commit 9d049426a6fb2976fa39c4642146ae4959a08709 in logging-log4j2's branch refs/heads/master from rpopma [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=9d04942 ] LOG4J2-1908 added comment and more javadoc
        Hide
        remkop@yahoo.com Remko Popma added a comment -

        Fixed in master. The above configuration now gives this error:

        2017-06-30 21:26:40,270 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender for element RollingRandomAccessFile org.apache.logging.log4j.core.config.ConfigurationException: Configuration has multiple incompatible Appenders pointing to the same file target/multiIncompatibleAppender.log
        	at org.apache.logging.log4j.core.appender.OutputStreamManager.narrow(OutputStreamManager.java:134)
        	at org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager.getRollingRandomAccessFileManager(RollingRandomAccessFileManager.java:104)
        	at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender$Builder.build(RollingRandomAccessFileAppender.java:125)
        	at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender$Builder.build(RollingRandomAccessFileAppender.java:50)
        	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
        	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
        	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
        	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
        	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
        	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
        	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
        	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
        	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
        	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:239)
        	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:159)
        	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:131)
        	at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:101)
        	at org.apache.logging.log4j.junit.LoggerContextRule$1.evaluate(LoggerContextRule.java:119)
        	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
        	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
        
        2017-06-30 21:26:40,273 main ERROR Null object returned for RollingRandomAccessFile in Appenders.
        
        Show
        remkop@yahoo.com Remko Popma added a comment - Fixed in master. The above configuration now gives this error: 2017-06-30 21:26:40,270 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender for element RollingRandomAccessFile org.apache.logging.log4j.core.config.ConfigurationException: Configuration has multiple incompatible Appenders pointing to the same file target/multiIncompatibleAppender.log at org.apache.logging.log4j.core.appender.OutputStreamManager.narrow(OutputStreamManager.java:134) at org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager.getRollingRandomAccessFileManager(RollingRandomAccessFileManager.java:104) at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender$Builder.build(RollingRandomAccessFileAppender.java:125) at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender$Builder.build(RollingRandomAccessFileAppender.java:50) at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122) at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890) at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513) at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237) at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249) at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545) at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:239) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:159) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:131) at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:101) at org.apache.logging.log4j.junit.LoggerContextRule$1.evaluate(LoggerContextRule.java:119) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 2017-06-30 21:26:40,273 main ERROR Null object returned for RollingRandomAccessFile in Appenders.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 9672576b3dd6aeb68df36f6698dc260e43d26cb3 in logging-log4j2's branch refs/heads/master from rpopma
        [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=9672576 ]

        LOG4J2-1908 Improved error message when misconfigured with multiple incompatible appenders targeting same file

        Show
        jira-bot ASF subversion and git services added a comment - Commit 9672576b3dd6aeb68df36f6698dc260e43d26cb3 in logging-log4j2's branch refs/heads/master from rpopma [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=9672576 ] LOG4J2-1908 Improved error message when misconfigured with multiple incompatible appenders targeting same file

          People

          • Assignee:
            remkop@yahoo.com Remko Popma
            Reporter:
            remkop@yahoo.com Remko Popma
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development