Package org.apache.solr.util
Class ErrorLogMuter
- java.lang.Object
-
- org.apache.solr.util.ErrorLogMuter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 includedThrowable
, or any of the recursiveThrowable.getCause()
es of an includedThrowable
.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
int
getCount()
The number of ERROR messages muted (by this instance) so far in it's lifecycle.static ErrorLogMuter
regex(String regex)
Mutes ERROR log messages that partially match the specified regex.static ErrorLogMuter
regex(Pattern pat)
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
-
-
-
Method Detail
-
substring
public static ErrorLogMuter substring(String substr)
Mutes ERROR log messages that contain the input as a substring
-
regex
public static ErrorLogMuter regex(String regex)
Mutes ERROR log messages that partially match the specified regex.- See Also:
Matcher.find()
-
regex
public static ErrorLogMuter regex(Pattern pat)
Mutes ERROR log messages that partially match the specified regex.- See Also:
Matcher.find()
-
getCount
public int getCount()
The number of ERROR messages muted (by this instance) so far in it's lifecycle. This number may be less then the number of ERROR messages expected if multiple ErrorLogMuter objects are in use which match the same ERROR log messages
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-