logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Srivastava, Satguru" <ssrivast...@Aegonusa.com>
Subject FallBackError Handler Bug?
Date Tue, 26 Sep 2006 16:39:46 GMT
I had sent this email to user list.
It probably belongs here.
 
I am having problem using AsyncAppender with the FallbackErrorHandler.
 
I have
a) a AsyncAppender attached to the root logger.
b) a JMSAppender attached to the AsyncAppender.
c) a FallbackErrorHandler attached to the JMSAppender. The
FallbackErrorHandler specifies the root as a logger (using root-ref tag)
and a FileAppender as the fallback appender (using appender-ref tag).
 
Now when an error occurs, the the FallbackErrorHandler tries to replace
the JMSAppender with the FileAppender in the root logger! (rather than
in the AsyncAppender).
Unfortunately this does not help, as the root logger keeps sending
messages to the AsyncAppender which then forwards them to the failing
JMSAppender.
 
Is this a bug or am I doing something wrong?
 
If this is a bug then ,I think, the FallbackErrorHandler should be
modified to check each of the loggers, specified to it , to see if any
of them have a AsyncAppender attached. 
If it finds one then it should try to switch the primary and backup
appender in that AsyncAppender rather than in the logger.
 
I got around my issue by modifying the FallbackErrorHandler to do just
that.
Could somebody look at the new code and let me know if this was really
required and if yes then if the changes I made are appropriate
Attached is the new code. 
 
I added a new method called "private void removeFromAsync(Logger l)" and
modified the 
"public void error(String message, Exception e, int errorCode,
LoggingEvent event)" to call this new method for each logger.
 
Thanks fro any help.
Sat
 
Here is just the modified code
==============================================
 /**
     Prints the message and the stack trace of the exception on
     <code>System.err</code>.
   */
  public
  void error(String message, Exception e, int errorCode, LoggingEvent
event) {
    LogLog.debug("FB: The following error reported: " + message, e);
    LogLog.debug("FB: INITIATING FALLBACK PROCEDURE.");
    if (loggers != null) {
     for(int i = 0; i < loggers.size(); i++) {
        Logger l = (Logger) loggers.elementAt(i);
        LogLog.debug("FB: Searching for ["+primary.getName()+"] in
logger ["
       +l.getName() + "].");
        LogLog.debug("FB: Replacing ["+primary.getName()+"] by ["
       + backup.getName() + "] in logger ["+ l.getName() +"].");
        l.removeAppender(primary);
        LogLog.debug("FB: Adding appender ["+backup.getName()+"] to
logger "
       +  l.getName());
        l.addAppender(backup);
   LogLog.debug("FB: Removing from Async now"); 
        removeFromAsync(l);
        }
    }
  }
 
  /**
     Check each appender in the logger to see if it is a AsyncAdapter.
     If yes then switch primary and backup appender.
   */
 
  private void removeFromAsync(Logger l){
   Enumeration appenders = l.getAllAppenders();
   Appender appdr;
   AsyncAppender aa;
   while (appenders.hasMoreElements()){
    appdr = (Appender) appenders.nextElement();
    if (appdr instanceof AsyncAppender){
   LogLog.debug("FB: Checking Async appender [" + appdr.getName()
+"].");
   aa = (AsyncAppender) appdr;
   if (aa.getAppender(primary.getName()) != null){
    LogLog.debug("FB: Replacing ["+primary.getName()+"] by ["
       + backup.getName() + "] in Aync Appender ["+ appdr.getName()
+"].");
    aa.removeAppender(primary);
    aa.addAppender(backup);
   }
  }
   }
  }
========================================================
 

Mime
View raw message