Class JansiConsoleAppender<E>

Type Parameters:
E - the type of logging events
All Implemented Interfaces:
Appender<E>, ContextAware, FilterAttachable<E>, LifeCycle

public class JansiConsoleAppender<E> extends ConsoleAppender<E>
A ConsoleAppender that always writes through JLine's AnsiConsole, enabling ANSI sequences on platforms that need Jansi (notably Windows).

Unlike ConsoleAppender's deprecated withJansi path, this class overrides wrapTarget(OutputStream) and calls AnsiConsole directly (no reflection). It requires org.jline:jansi-core on the classpath.

AnsiConsole.systemInstall() is paired with AnsiConsole.systemUninstall() on stop() when this appender performed the install. Console streams are still only flushed on stop (not closed); see ConsoleAppender.closeOutputStream().

Since:
1.6.3
Author:
Ceki Gülcü
See Also:
  • Constructor Details

  • Method Details

    • stop

      public void stop()
      Flushes the console stream (via OutputStreamAppender.stop()), then undoes AnsiConsole.systemInstall() if this appender performed it.
      Specified by:
      stop in interface LifeCycle
      Overrides:
      stop in class OutputStreamAppender<E>
    • wrapTarget

      protected OutputStream wrapTarget(OutputStream targetStream)
      Installs Jansi and returns AnsiConsole.out() or AnsiConsole.err() according to the configured target.

      Does not use the deprecated withJansi / wrapWithJansi path. AnsiConsole.systemInstall() is invoked at most once per install ownership of this instance.

      If JLINE_JANSI_ANSI_CONSOLE_CLASS_NAME is not loadable, a warning is emitted and targetStream is returned unchanged.

      Overrides:
      wrapTarget in class ConsoleAppender<E>
      Parameters:
      targetStream - the raw stream for ConsoleAppender.target
      Returns:
      the stream to use as this appender's output stream