Class LoggerUtils

java.lang.Object
reactor.test.util.LoggerUtils

public final class LoggerUtils extends Object
This class eases testing interested in what reactor classes emit using loggers.
Author:
Eric Bottard
  • Method Details

    • useCurrentLoggersWithCapture

      public static Disposable useCurrentLoggersWithCapture() throws IllegalStateException
      Sets a logger factory that will return loggers that not only use the original logging framework used by reactor, but also use the logger set via enableCaptureWith(Logger), irrespective of its name or how it was obtained. The expectation here is that tests that want to assess that something is logged by reactor will pass a TestLogger instance to enableCaptureWith(Logger), trigger the operation under scrutiny, assert the logger contents and reset state by calling disableCapture().

      This method should be called very early in the application/tests lifecycle, before reactor classes have created their loggers.

      Returns:
      a disposable that re-installs the original factory when disposed
      Throws:
      IllegalStateException
    • enableCaptureWith

      public static void enableCaptureWith(Logger testLogger)
      Set the logger used for capturing.
      Parameters:
      testLogger - the Logger in which to copy logs
      Throws:
      IllegalStateException - if no capturing factory is installed or a previous logger has been set but not cleared via disableCapture()
    • enableCaptureWith

      public static void enableCaptureWith(Logger testLogger, boolean redirectToOriginal)
      Set the logger used for capturing, an optionally suppress log messages from original logger.
      Parameters:
      testLogger - the TestLogger in which to copy or redirect logs
      redirectToOriginal - whether log messages should also go to the original logging infrastructure
      Throws:
      IllegalStateException - if no capturing factory is installed or a previous logger has been set but not cleared via disableCapture()
    • disableCapture

      public static void disableCapture()
      Disable capturing, forgetting about the logger set via enableCaptureWith(Logger).