public final class TestLoggers extends Object implements org.slf4j.ILoggerFactory
Modifier and Type | Field and Description |
---|---|
static boolean |
EXECUTED_FROM_IDE |
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.
|
<R> LogCollection<R> |
collect(String category,
Level fromLevel,
Level toLevel,
boolean passThrough,
Collector<LogRecord,?,R> collector,
ToIntFunction<List<LogHandler>> whereTo) |
<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,
long timeout,
TimeUnit unit,
org.hamcrest.Matcher<LogRecord>... matchers) |
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,
long timeout,
TimeUnit unit,
org.hamcrest.Matcher<LogRecord>... matchers) |
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();
|
LogAssert |
expectUncaughtException(long timeout,
TimeUnit unit,
org.hamcrest.Matcher<UncaughtExceptionDetail> matcher)
Assert uncaught exceptions.(from threads)
|
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.
|
void |
interceptInContext(String category,
LogHandler handler) |
void |
print(String category,
Level level)
Print logs above a category and log level.
|
void |
print(String category,
Level level,
boolean greedy) |
static TestLoggers |
sys() |
String |
toString() |
public static TestLoggers sys()
public LogConfig getConfig()
public void 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 void interceptInContext(String category, LogHandler handler)
@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 <R> LogCollection<R> collect(String category, Level fromLevel, Level toLevel, boolean passThrough, Collector<LogRecord,?,R> collector, ToIntFunction<List<LogHandler>> whereTo)
@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 expect(String category, Level minimumLogLevel, long timeout, TimeUnit unit, org.hamcrest.Matcher<LogRecord>... matchers)
@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.public LogAssert expect(String category, Level minimumLogLevel, int nrTimes, long timeout, TimeUnit unit, org.hamcrest.Matcher<LogRecord>... matchers)
@Beta public LogAssert expectUncaughtException(long timeout, TimeUnit unit, org.hamcrest.Matcher<UncaughtExceptionDetail> matcher)
timeout
- timeout to wait for this assertion. from the point in time of assertion invocation.unit
- 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.