Class Reload4jLoggerContext


  • public final class Reload4jLoggerContext
    extends Object
    Reload4jLoggerContext represents a reload4j Logger. It can be injected using TestLogger, TestLogger.ForClass or TestLogger.Root, and can be used to configure the logger for test purposes.

    Note: reloadj4 is based on Log4j 1.x. As a result, this class can most likely also be used with Log4j 1.x. However, no guarantees are made.

    Author:
    Rob Spoor
    Since:
    2.1
    • Method Detail

      • setAppender

        public Reload4jLoggerContext setAppender​(Appender appender)
        Sets the single appender for the logger. All existing appenders will first be removed.
        Parameters:
        appender - The appender to set.
        Returns:
        This object.
        Throws:
        NullPointerException - If the given appender is null.
      • removeAppender

        public Reload4jLoggerContext removeAppender​(Appender appender)
        Removes an appender from the logger.
        Parameters:
        appender - The appender to remove.
        Returns:
        This object.
        Throws:
        NullPointerException - If the given appender is null.
      • removeAppenders

        public Reload4jLoggerContext removeAppenders()
        Removes all appenders from the logger.
        Returns:
        This object.
      • useParentAppenders

        public Reload4jLoggerContext useParentAppenders​(boolean useParentAppenders)
        Sets whether or not to use parent appenders for the logger.
        Parameters:
        useParentAppenders - true to use parent appenders, false otherwise.
        Returns:
        This object.
      • capture

        public LogCaptor<LoggingEvent> capture()
        Returns an object that captures logged events. This can be used instead of having to append a capturing appender manually.
        Returns:
        An object that captures logged events.
        Since:
        3.0
      • restore

        public void restore()
        Restores the original settings of the logger.

        It should usually not be necessary to call this method, as it will be called automatically once this context goes out of scope.