Class LogUtils

java.lang.Object
nva.commons.logutils.LogUtils

public final class LogUtils extends 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 Details

  • Method Details

    • getTestingAppender

      public static <T> TestAppender getTestingAppender(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 String toLoggerName(Class<?> cls)
      From LogManager.getLogger()
      Parameters:
      cls - the class
      Returns:
      the logger name