Class 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 Detail

      • substring

        public static ErrorLogMuter substring​(String substr)
        Mutes ERROR log messages that contain the input as a substring
      • 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