Class JansiConsoleAppender<E>
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<E>
ch.qos.logback.core.OutputStreamAppender<E>
ch.qos.logback.core.ConsoleAppender<E>
ch.qos.logback.core.JansiConsoleAppender<E>
- Type Parameters:
E- the type of logging events
- All Implemented Interfaces:
Appender<E>, ContextAware, FilterAttachable<E>, LifeCycle
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:
-
Field Summary
Fields inherited from class ConsoleAppender
FUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAME, preferredJansiClassName, target, withJansiFields inherited from class OutputStreamAppender
encoder, streamWriteLockFields inherited from class UnsynchronizedAppenderBase
name, startedFields inherited from class ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidstop()Flushes the console stream (viaOutputStreamAppender.stop()), then undoesAnsiConsole.systemInstall()if this appender performed it.protected OutputStreamwrapTarget(OutputStream targetStream) Installs Jansi and returnsAnsiConsole.out()orAnsiConsole.err()according to the configured target.Methods inherited from class ConsoleAppender
buildReentryGuard, closeOutputStream, getPreferredJansiClassName, getTarget, isWithJansi, setPreferredJansiClassName, setTarget, setWithJansi, start, wrapWithJansiMethods inherited from class OutputStreamAppender
append, getEncoder, getOutputStream, isImmediateFlush, setEncoder, setImmediateFlush, setLayout, setOutputStream, subAppend, updateByteCount, writeByteArrayToOutputStreamWithPossibleFlush, writeOutMethods inherited from class UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringMethods inherited from class ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Constructor Details
-
JansiConsoleAppender
public JansiConsoleAppender()
-
-
Method Details
-
stop
Flushes the console stream (viaOutputStreamAppender.stop()), then undoesAnsiConsole.systemInstall()if this appender performed it.- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classOutputStreamAppender<E>
-
wrapTarget
Installs Jansi and returnsAnsiConsole.out()orAnsiConsole.err()according to the configured target.Does not use the deprecated
withJansi/wrapWithJansipath.AnsiConsole.systemInstall()is invoked at most once per install ownership of this instance.If
JLINE_JANSI_ANSI_CONSOLE_CLASS_NAMEis not loadable, a warning is emitted andtargetStreamis returned unchanged.- Overrides:
wrapTargetin classConsoleAppender<E>- Parameters:
targetStream- the raw stream forConsoleAppender.target- Returns:
- the stream to use as this appender's output stream
-