Bug 37638

Summary: logging doesn't fall back with FallbackErrorHandler if PRIMARY appender is used by multiple loggers
Product: Log4j - Now in Jira Reporter: Andrei Savitski <as85586>
Component: OtherAssignee: log4j-dev <log4j-dev>
Status: NEW ---    
Severity: normal Keywords: ErrorMessage
Priority: P2    
Version: 1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Attachments: Test case that demonstrates problem with multiply attached fallbackerrorhandler

Description Andrei Savitski 2005-11-25 15:05:45 UTC
With standart config from sample for FallbackErrorHandler everything works 
fine. But if you'll add anoher logger using PRIMARY appender, than nothing will 
appear in log file specified for backup appender.

Here is con file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration debug="true" 
xmlns:log4j="http://jakarta.apache.org/log4j/">
  
  <appender name="PRIMARY" class="org.apache.log4j.FileAppender">
    <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
      <root-ref/>
      <appender-ref ref="FALLBACK" />
    </errorHandler>
    <param name="File" value="xyz/z.log" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
    </layout>
  </appender>

  <appender name="FALLBACK" class="org.apache.log4j.FileAppender">
    <param name="File" value="fallback.log" />
    <param name="Append" value="false" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="--%d %p %t %c - %m%n"/>
    </layout>
  </appender>

  <logger name="org.mailbox">
    <level value="warn" />
    <appender-ref ref="PRIMARY" />
  </logger>

  <root>
    <level value="debug" />
    <appender-ref ref="PRIMARY" />
  </root>

</log4j:configuration>

To reproduce bug, just make first log file readonly.
Comment 1 Curt Arnold 2009-10-08 21:04:39 UTC
Created attachment 24366 [details]
Test case that demonstrates problem with multiply attached fallbackerrorhandler
Comment 2 Curt Arnold 2009-10-08 21:07:24 UTC
The sample configuration only specifies falling back on the root logger.  If there was a failure, only the root logger would be switched to the FALLBACK appender.  The "org.mailbox" logger would keep the failed PRIMARY appender.

I've attached a test case that is a variant of the existing ErrorHandlerTestCase that should have worked, but at least for errors that occur during configuration, something closes FALLBACK appender before it can output anything.  Likely some unfortunately interaction between the configurator and the FallbackErrorHandler.