Class MockLogAppender
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.appender.AbstractAppender
org.opensearch.test.MockLogAppender
- All Implemented Interfaces:
AutoCloseable,org.apache.logging.log4j.core.Appender,org.apache.logging.log4j.core.filter.Filterable,org.apache.logging.log4j.core.impl.LocationAware,org.apache.logging.log4j.core.LifeCycle,org.apache.logging.log4j.core.LifeCycle2
public class MockLogAppender
extends org.apache.logging.log4j.core.appender.AbstractAppender
implements AutoCloseable
Test appender that can be used to verify that certain events were logged correctly
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic interfacestatic classstatic classUsed for cases when the logger is dynamically named such as to include an index name or shard id Best used in conjunction with the root logger:@TestLogging(value = "_root:debug", reason = "Validate logging output");static classstatic classNested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
org.apache.logging.log4j.core.appender.AbstractAppender.Builder<B extends org.apache.logging.log4j.core.appender.AbstractAppender.Builder<B>>Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
org.apache.logging.log4j.core.LifeCycle.State -
Field Summary
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERFields inherited from interface org.apache.logging.log4j.core.Appender
ELEMENT_TYPE, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpectation(MockLogAppender.LoggingExpectation expectation) voidappend(org.apache.logging.log4j.core.LogEvent event) voidvoidclose()static MockLogAppendercreateForLoggers(String filter, org.apache.logging.log4j.Logger... loggers) static MockLogAppendercreateForLoggers(org.apache.logging.log4j.Logger... loggers) Creates an instance and adds it as an appender to the given Loggers.voidstop()Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toStringMethods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, start, stop, stopMethods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.core.LifeCycle
getState, initialize, isStarted, isStopped, start
-
Method Details
-
createForLoggers
public static MockLogAppender createForLoggers(org.apache.logging.log4j.Logger... loggers) throws IllegalAccessException Creates an instance and adds it as an appender to the given Loggers. Upon closure, this instance will then remove itself from the Loggers it was added to. It is strongly recommended to use this class in a try-with-resources block to guarantee that it is properly removed from all Loggers. Since the logging state is static and therefore global within a JVM, it can cause unrelated tests to fail if, for example, they trigger a logging statement that tried to write to a closed MockLogAppender instance.- Throws:
IllegalAccessException
-
createForLoggers
public static MockLogAppender createForLoggers(String filter, org.apache.logging.log4j.Logger... loggers) throws IllegalAccessException - Throws:
IllegalAccessException
-
addExpectation
-
append
public void append(org.apache.logging.log4j.core.LogEvent event) - Specified by:
appendin interfaceorg.apache.logging.log4j.core.Appender
-
assertAllExpectationsMatched
public void assertAllExpectationsMatched() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
stop
public void stop()- Specified by:
stopin interfaceorg.apache.logging.log4j.core.LifeCycle- Overrides:
stopin classorg.apache.logging.log4j.core.AbstractLifeCycle
-