public final class ErrorLogMuter extends Object implements Closeable, AutoCloseable
Helper code for "Muting" ERROR log messages that you expect as a result of the things you are testing, so they aren't a distraction in test logs. Example usage...
try (ErrorLogMuter errors = ErrorLogMuter.substring("nullfirst")) {
assertQEx( "invalid query format",
req( "q","id_i:1000", "sort", "nullfirst" ), 400 );
assertEquals(1, errors.getCount());
}
ERROR messages are considered a match if their input matches either the message String, or the toString
of an included
Throwable
, or any of the recursive Throwable.getCause()
es of an included Throwable
.
Matching ERROR messages are "muted" by filtering them out of the ROOT logger. Any Appenders attached to more specific Loggers may still include these "muted" ERRROR messages.
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getCount()
The number of ERROR messages muted (by this instance) so far in it's lifecycle.
|
static ErrorLogMuter |
regex(Pattern pat)
Mutes ERROR log messages that partially match the specified regex.
|
static ErrorLogMuter |
regex(String regex)
Mutes ERROR log messages that partially match the specified regex.
|
static ErrorLogMuter |
substring(String substr)
Mutes ERROR log messages that contain the input as a substring
|
public static ErrorLogMuter substring(String substr)
public static ErrorLogMuter regex(String regex)
Matcher.find()
public static ErrorLogMuter regex(Pattern pat)
Matcher.find()
public int getCount()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.