- 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
public class JansiConsoleAppender<E> extends ConsoleAppender<E>
AConsoleAppenderthat always writes through JLine'sAnsiConsole, enabling ANSI sequences on platforms that need Jansi (notably Windows).Unlike
ConsoleAppender's deprecatedwithJansipath, this class overrideswrapTarget(OutputStream)and callsAnsiConsoledirectly (no reflection). It requiresorg.jline:jansi-coreon the classpath.AnsiConsole.systemInstall()is paired withAnsiConsole.systemUninstall()onstop()when this appender performed the install. Console streams are still only flushed on stop (not closed); seeConsoleAppender.closeOutputStream().- Since:
- 1.6.3
- Author:
- Ceki Gülcü
- See Also:
AnsiConsole,ConsoleAppender.wrapTarget(OutputStream)
-
-
Field Summary
-
Fields inherited from class ch.qos.logback.core.ConsoleAppender
FUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAME, preferredJansiClassName, target, withJansi
-
Fields inherited from class ch.qos.logback.core.OutputStreamAppender
encoder, streamWriteLock
-
Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
name, started
-
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
-
Constructor Summary
Constructors Constructor Description JansiConsoleAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidstop()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 ch.qos.logback.core.ConsoleAppender
buildReentryGuard, closeOutputStream, getPreferredJansiClassName, getTarget, isWithJansi, setPreferredJansiClassName, setTarget, setWithJansi, start, wrapWithJansi
-
Methods inherited from class ch.qos.logback.core.OutputStreamAppender
append, getEncoder, getOutputStream, isImmediateFlush, setEncoder, setImmediateFlush, setLayout, setOutputStream, subAppend, updateByteCount, writeByteArrayToOutputStreamWithPossibleFlush, writeOut
-
Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
-
-
-
Constructor Detail
-
JansiConsoleAppender
public JansiConsoleAppender()
-
-
Method Detail
-
stop
public void stop()
Flushes the console stream (viaOutputStreamAppender.stop()), then undoesAnsiConsole.systemInstall()if this appender performed it.- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classOutputStreamAppender<E>
-
wrapTarget
protected OutputStream wrapTarget(OutputStream targetStream)
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
-
-