FileDocCategorySizeDatePackage
FallbackErrorHandler.javaAPI DocApache log4j 1.2.153820Sat Aug 25 00:09:40 BST 2007org.apache.log4j.varia

FallbackErrorHandler

public class FallbackErrorHandler extends Object implements ErrorHandler
The FallbackErrorHandler implements the ErrorHandler interface such that a secondary appender may be specified. This secondary appender takes over if the primary appender fails for whatever reason.

The error message is printed on System.err, and logged in the new secondary appender.

author
Ceki Gücü

Fields Summary
Appender
backup
Appender
primary
Vector
loggers
Constructors Summary
public FallbackErrorHandler()

  
Methods Summary
public voidactivateOptions()
No options to activate.

  
public voiderror(java.lang.String message, java.lang.Exception e, int errorCode)
Prints the message and the stack trace of the exception on System.err.

 
    error(message, e, errorCode, null);
  
public voiderror(java.lang.String message, java.lang.Exception e, int errorCode, org.apache.log4j.spi.LoggingEvent event)
Prints the message and the stack trace of the exception on System.err.

    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);
        }
    }    
  
public voiderror(java.lang.String message)
Print a the error message passed as parameter on System.err.

    //if(firstTime) {
    //LogLog.error(message);
    //firstTime = false;
    //}
  
public voidsetAppender(org.apache.log4j.Appender primary)
The appender to which this error handler is attached.

    LogLog.debug("FB: Setting primary appender to [" + primary.getName() + "].");
    this.primary = primary;
  
public voidsetBackupAppender(org.apache.log4j.Appender backup)
Set the backup appender.

    LogLog.debug("FB: Setting backup appender to [" + backup.getName() + "].");
    this.backup = backup;
  
public voidsetLogger(org.apache.log4j.Logger logger)
Adds the logger passed as parameter to the list of loggers that we need to search for in case of appender failure.

    LogLog.debug("FB: Adding logger [" + logger.getName() + "].");
    if(loggers == null) {
      loggers = new Vector();
    }
    loggers.addElement(logger);