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" 
  <appender name="PRIMARY" class="org.apache.log4j.FileAppender">
    <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
      <appender-ref ref="FALLBACK" />
    <param name="File" value="xyz/z.log" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>

  <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"/>

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

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


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.