Package io.helidon.common.testing.junit5
Class InMemoryLoggingHandler
java.lang.Object
java.util.logging.Handler
io.helidon.common.testing.junit5.InMemoryLoggingHandler
- All Implemented Interfaces:
AutoCloseable
Captures log records in memory for later retrieval.
The handler is intended to be attached to a single logger. Callers can use the static factory methods to create an in-memory handler and attach it to the specified logger. The handler is auto-closable so a properly-constructed test--using try-with-resource--will automatically clear the handler's log records and detach the handler from the logger.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static InMemoryLoggingHandler
Creates a new in-memory logging handler and attaches it to the logger named after the class name of the specified object.static InMemoryLoggingHandler
Creates a new in-memory logging handler and attaches it to the specified logger.void
flush()
Returns the accumulated log records.void
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
Method Details
-
create
Creates a new in-memory logging handler and attaches it to the specified logger.- Parameters:
logger
- theLogger
to which to add a new in-memory handler- Returns:
- the new handler
-
create
Creates a new in-memory logging handler and attaches it to the logger named after the class name of the specified object.- Parameters:
objectWithNamedLogger
- the object whose class-name-based logger the handler should be added to- Returns:
- the new handler
-
publish
-
flush
public void flush() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classHandler
- Throws:
SecurityException
-
logRecords
Returns the accumulated log records.- Returns:
- list of log records
-