Package nva.commons.logutils
Class LogUtils
- java.lang.Object
-
- nva.commons.logutils.LogUtils
-
public final class LogUtils extends java.lang.ObjectMethods for testing logging when using Log4j2 as logging platform. Can be used when using SLF4J as well with Log4j2 as background logging platform.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringLOG_CLASS_NAME_AND_MESSAGEstatic java.lang.StringPACKAGES_WITH_APPENDERSstatic java.lang.StringPATTERN_ATTRIBUTE_NAMEstatic java.lang.StringROOT_NULL_APPENDER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TestAppendergetTestingAppender(java.lang.Class<T> clazz)This method should ALWAYS be called before the creation of the object you want to test.static <T> TestAppendergetTestingAppenderForRootLogger()This method should ALWAYS be called before the creation of the object you want to test.static java.lang.StringtoLoggerName(java.lang.Class<?> cls)From LogManager.getLogger()
-
-
-
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
-
-