Class LogUtils


  • public final class LogUtils
    extends java.lang.Object
    Methods for testing logging when using Log4j2 as logging platform. Can be used when using SLF4J as well with Log4j2 as background logging platform.
    • Field Detail

      • PATTERN_ATTRIBUTE_NAME

        public static final java.lang.String PATTERN_ATTRIBUTE_NAME
        See Also:
        Constant Field Values
      • LOG_CLASS_NAME_AND_MESSAGE

        public static final java.lang.String LOG_CLASS_NAME_AND_MESSAGE
        See Also:
        Constant Field Values
      • ROOT_NULL_APPENDER

        public static final java.lang.String ROOT_NULL_APPENDER
        See Also:
        Constant Field Values
      • PACKAGES_WITH_APPENDERS

        public static final java.lang.String PACKAGES_WITH_APPENDERS
        See Also:
        Constant Field Values
    • Method Detail

      • getTestingAppender

        public static <T> TestAppender getTestingAppender​(java.lang.Class<T> clazz)
        This method should ALWAYS be called before the creation of the object you want to test.

        The method was created based on the patterns for programmatically configuring Log4j (https://logging.apache.org/log4j/2.x/manual/customconfig.html)

        Type Parameters:
        T - The class of the object under test
        Parameters:
        clazz - The class of the object under test.
        Returns:
        a TestAppender
      • getTestingAppenderForRootLogger

        public static <T> TestAppender getTestingAppenderForRootLogger()
        This method should ALWAYS be called before the creation of the object you want to test.

        The method was created based on the patterns for programmatically configuring Log4j (https://logging.apache.org/log4j/2.x/manual/customconfig.html)

        Type Parameters:
        T - The class of the object under test
        Returns:
        a TestAppender
      • toLoggerName

        public static java.lang.String toLoggerName​(java.lang.Class<?> cls)
        From LogManager.getLogger()
        Parameters:
        cls - the class
        Returns:
        the logger name