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 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.

  • Method Details

    • 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:
    • regex

      public static ErrorLogMuter regex(Pattern pat)
      Mutes ERROR log messages that partially match the specified regex.
      See Also:
    • 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 interface AutoCloseable
      Specified by:
      close in interface Closeable