public final class TestLoggers extends Object implements org.slf4j.ILoggerFactory
Modifier and Type | Method and Description |
---|---|
LogCollection<ArrayDeque<LogRecord>> |
collect(Level minimumLogLevel,
int maxNrLogs,
boolean collectPrinted)
Collect up to a number of log messages.
|
<T> LogCollection<T> |
collect(String category,
Level fromLevel,
boolean passThrough,
Collector<LogRecord,?,T> collector)
Collect a bunch of logs.
|
<T> LogCollection<T> |
collect(String category,
Level fromLevel,
Level toLevel,
boolean passThrough,
Collector<LogRecord,?,T> collector)
Collect a bunch of logs.
|
LogAssert |
dontExpect(String category,
Level minimumLogLevel,
org.hamcrest.Matcher<LogRecord>... matchers)
the opposite of expect.
|
LogAssert |
expect(String category,
Level minimumLogLevel,
int nrTimes,
org.hamcrest.Matcher<LogRecord>... matchers)
Ability to assert is you expect a sequence of logs to be repeated.
|
LogAssert |
expect(String category,
Level minimumLogLevel,
org.hamcrest.Matcher<LogRecord>... matchers)
Create an log expectation that can be asserted like:
LogAssert expect = TestLoggers.expect("org.spf4j.test", Level.ERROR, Matchers.hasProperty("format",
Matchers.equalTo("Booo")));
LOG.error("Booo", new RuntimeException());
expect.assertObservation();
|
AsyncObservationAssert |
expectUncaughtException(org.hamcrest.Matcher<UncaughtExceptionDetail> matcher)
Assert uncaught exceptions.
|
LogConfig |
getConfig() |
Logger |
getJulGlobal() |
Logger |
getJulRoot() |
org.slf4j.Logger |
getLogger(String name)
Return an appropriate
SimpleLogger instance by name. |
HandlerRegistration |
ignore(String category,
Level from,
Level to)
all logs from category and specified levels will be ignored...
|
HandlerRegistration |
intercept(String category,
LogHandler handler)
Ability to intercept log messages logged under a category
|
HandlerRegistration |
interceptAllLevels(String category,
AllLevelsLogHandler handler)
Convenience method for functional use.
|
HandlerRegistration |
print(String category,
Level level)
Print logs above a category and log level.
|
static TestLoggers |
sys() |
String |
toString() |
public static TestLoggers sys()
public LogConfig getConfig()
@CheckReturnValue public HandlerRegistration print(String category, Level level)
category
- the log category.level
- the log level.@CheckReturnValue public HandlerRegistration intercept(String category, LogHandler handler)
category
- the logger category name (a.b.c)handler
- the log handler to register.@CheckReturnValue public <T> LogCollection<T> collect(String category, Level fromLevel, boolean passThrough, Collector<LogRecord,?,T> collector)
T
- the type of object to collect into.category
- the log category (a.b.c)fromLevel
- from level to collect.passThrough
- pass the logs to lower category handlers or not.collector
- the collector to collect the logs.@CheckReturnValue public <T> LogCollection<T> collect(String category, Level fromLevel, Level toLevel, boolean passThrough, Collector<LogRecord,?,T> collector)
T
- the type of object to collect into.category
- the log category (a.b.c)fromLevel
- from level to collect.toLevel
- to level to collect.passThrough
- pass the logs to lower category handlers or not.collector
- the collector to collect the logs.@CheckReturnValue public HandlerRegistration interceptAllLevels(String category, AllLevelsLogHandler handler)
category
- the log category.handler
- a functional handler.@CheckReturnValue public HandlerRegistration ignore(String category, Level from, Level to)
category
- the log category.from
- from log level.to
- to log level.@CheckReturnValue public LogAssert expect(String category, Level minimumLogLevel, org.hamcrest.Matcher<LogRecord>... matchers)
LogAssert expect = TestLoggers.expect("org.spf4j.test", Level.ERROR, Matchers.hasProperty("format",
Matchers.equalTo("Booo")));
LOG.error("Booo", new RuntimeException());
expect.assertObservation();
category
- the category under which we should expect these messages.minimumLogLevel
- minimum log level of expected log messagesmatchers
- a succession of LogMessages with each matching a Matcher is expected.@CheckReturnValue public LogAssert dontExpect(String category, Level minimumLogLevel, org.hamcrest.Matcher<LogRecord>... matchers)
category
- the category under which we should expect these messages.minimumLogLevel
- minimum log level of expected log messagesmatchers
- a succession of LogMessages with each matching a Matcher is NOT expected.public LogAssert expect(String category, Level minimumLogLevel, int nrTimes, org.hamcrest.Matcher<LogRecord>... matchers)
category
- the log category (a.b.c)minimumLogLevel
- the minimum log level of expected messages.nrTimes
- number of time the sequence should appear.matchers
- the sequence of matchers.@Beta public AsyncObservationAssert expectUncaughtException(org.hamcrest.Matcher<UncaughtExceptionDetail> matcher)
matcher
- the exception matcher.public LogCollection<ArrayDeque<LogRecord>> collect(Level minimumLogLevel, int maxNrLogs, boolean collectPrinted)
minimumLogLevel
- the minimum log level of the messages.maxNrLogs
- the max number of messages to collect.collectPrinted
- collect messages that have been printed or not.public org.slf4j.Logger getLogger(String name)
SimpleLogger
instance by name.getLogger
in interface org.slf4j.ILoggerFactory
public Logger getJulGlobal()
public Logger getJulRoot()
Copyright © 2018 SPF4J. All rights reserved.