Class OnlyOnceErrorHandler

  • All Implemented Interfaces:
    ErrorHandler, OptionHandler

    public class OnlyOnceErrorHandler
    extends java.lang.Object
    implements ErrorHandler
    The OnlyOnceErrorHandler implements log4j's default error handling policy which consists of emitting a message for the first error in an appender and ignoring all following errors.

    The error message is printed on System.err.

    This policy aims at protecting an otherwise working application from being flooded with error messages when logging fails.

    Since:
    0.9.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.lang.String ERROR_PREFIX  
      (package private) boolean firstTime  
      (package private) java.lang.String WARN_PREFIX  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void activateOptions()
      No options to activate.
      void error​(java.lang.String message)
      Print a the error message passed as parameter on System.err.
      void error​(java.lang.String message, java.lang.Exception e, int errorCode)
      Prints the message and the stack trace of the exception on System.err.
      void error​(java.lang.String message, java.lang.Exception e, int errorCode, LoggingEvent event)
      Prints the message and the stack trace of the exception on System.err.
      void setAppender​(Appender appender)
      Does not do anything.
      void setBackupAppender​(Appender appender)
      Does not do anything.
      void setLogger​(Logger logger)
      Does not do anything.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OnlyOnceErrorHandler

        public OnlyOnceErrorHandler()
    • Method Detail

      • setLogger

        public void setLogger​(Logger logger)
        Does not do anything.
        Specified by:
        setLogger in interface ErrorHandler
        Parameters:
        logger - One of the loggers that will be searched for the failing appender in view of replacement.
      • error

        public void error​(java.lang.String message,
                          java.lang.Exception e,
                          int errorCode)
        Prints the message and the stack trace of the exception on System.err.
        Specified by:
        error in interface ErrorHandler
      • error

        public void error​(java.lang.String message,
                          java.lang.Exception e,
                          int errorCode,
                          LoggingEvent event)
        Prints the message and the stack trace of the exception on System.err.
        Specified by:
        error in interface ErrorHandler
        Parameters:
        message - The message assoicated with the error.
        e - The Exption that was thrown when the error occured.
        errorCode - The error code associated with the error.
        event - The logging event that the failing appender is asked to log.
      • error

        public void error​(java.lang.String message)
        Print a the error message passed as parameter on System.err.
        Specified by:
        error in interface ErrorHandler