Class OutputToLoggerRedirector

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public final class OutputToLoggerRedirector extends PrintStream
Redirect System.out.println() calls to an SLF4J-based logger.
Author:
Laurent Cohen
  • Method Details

    • enableForClass

      public static void enableForClass(Class<?> clazz)
      Enable forwarding System.out.println calls to the logger if the stacktrace contains the class parameter.
      Parameters:
      clazz - the class whose output to redirect.
    • enableForPackage

      public static void enableForPackage(String packageToLog)
      Enable forwarding System.out.println calls to the logger if the stacktrace contains the package parameter.
      Parameters:
      packageToLog - the name of the package whose output to redirect.
    • disable

      public static void disable()
      Disable forwarding to the logger resetting the standard output to the console.
    • println

      public void println(String line)
      Overrides:
      println in class PrintStream