- All Implemented Interfaces:
Appender<E>,ContextAware,FilterAttachable<E>,LifeCycle
- Direct Known Subclasses:
JansiConsoleAppender
System.out or
System.err using a layout specified by the user. The default
target is System.out.
For more information about this appender, please refer to the online manual at http://logback.qos.ch/manual/appenders.html#ConsoleAppender
This appender does not own the console streams it writes to. On stop it flushes those streams but does not close them, so process-wide stdout/stderr (and Jansi streams wrapping them) remain usable after reconfiguration.
- Author:
- Ceki Gülcü, Tom SH Liu, Ruediger Dohna
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected Stringprotected ConsoleTargetprotected booleanFields inherited from class ch.qos.logback.core.OutputStreamAppender
encoder, streamWriteLockFields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
name, startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ReentryGuardCreate a ThreadLocal ReentryGuard to prevent recursive appender invocations.protected voidFlush the console target without closing it.Returns the current value of the target property.booleanDeprecated.voidsetPreferredJansiClassName(String preferredJansiClassName) It allows to force Jansi class name used for probing.voidSets the value of the Target option.voidsetWithJansi(boolean withJansi) Deprecated.UseJansiConsoleAppenderinstead.voidstart()Checks that requires parameters are set and if everything is in order, activates this appender.protected OutputStreamwrapTarget(OutputStream targetStream) Optionally wraps the raw console target stream before it is used for logging.protected OutputStreamwrapWithJansi(OutputStream targetStream) Deprecated.UseJansiConsoleAppender/ overridewrapTarget(OutputStream).Methods inherited from class ch.qos.logback.core.OutputStreamAppender
append, getEncoder, getOutputStream, isImmediateFlush, setEncoder, setImmediateFlush, setLayout, setOutputStream, stop, subAppend, updateByteCount, writeByteArrayToOutputStreamWithPossibleFlush, writeOutMethods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
target
-
withJansi
-
JLINE_JANSI_ANSI_CONSOLE_CLASS_NAME
- See Also:
-
FUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAME
- See Also:
-
preferredJansiClassName
-
-
Constructor Details
-
ConsoleAppender
public ConsoleAppender()
-
-
Method Details
-
setTarget
Sets the value of the Target option. Recognized values are "System.out" and "System.err". Any other value will be ignored. -
getTarget
Returns the current value of the target property. The default value of the option is "System.out".See also
setTarget(java.lang.String). -
getPreferredJansiClassName
- Returns:
- the preferred Jansi class name
-
setPreferredJansiClassName
It allows to force Jansi class name used for probing.Used for testing purposes.
Valid values are
JLINE_JANSI_ANSI_CONSOLE_CLASS_NAMEandFUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAME.- Parameters:
preferredJansiClassName- the preferred Jansi class name- Since:
- 1.6.1
-
start
Description copied from class:OutputStreamAppenderChecks that requires parameters are set and if everything is in order, activates this appender.- Specified by:
startin interfaceLifeCycle- Overrides:
startin classOutputStreamAppender<E>
-
closeOutputStream
Flush the console target without closing it.System.out,System.err, and Jansi streams built onFileDescriptor.out/errare process-wide resources. Closing them fromOutputStreamAppender.stop()would poison stdout for the rest of the JVM (see issue #1063). The non-JansiConsoleTargetstreams already no-op onclose(); this override keeps the same contract when Jansi is used.- Overrides:
closeOutputStreamin classOutputStreamAppender<E>
-
buildReentryGuard
Create a ThreadLocal ReentryGuard to prevent recursive appender invocations.- Overrides:
buildReentryGuardin classUnsynchronizedAppenderBase<E>- Returns:
- a ReentryGuard instance of type
THREAD_LOCAL.
-
wrapTarget
Optionally wraps the raw console target stream before it is used for logging.The default implementation applies the deprecated
withJansireflection path whenwithJansiis true. Subclasses such asJansiConsoleAppendershould override this method to supply an alternate stream (without relying onwithJansi).- Parameters:
targetStream- the raw stream fortarget- Returns:
- the stream to use as this appender's output stream
- Since:
- 1.6.3
-
wrapWithJansi
Deprecated.UseJansiConsoleAppender/ overridewrapTarget(OutputStream).Wraps the console target stream with a Jansi ANSI-aware stream using reflection.This path is deprecated. Prefer
JansiConsoleAppender, which overrideswrapTarget(OutputStream)and callsorg.jline.jansi.AnsiConsoledirectly.- Parameters:
targetStream- the raw console target stream- Returns:
- a Jansi-backed stream, or
targetStreamon failure
-
isWithJansi
Deprecated.- Returns:
- whether to use JANSI or not.
-
setWithJansi
Deprecated.UseJansiConsoleAppenderinstead.If true, this appender will output to a stream provided by the JANSI library via reflection.This option is deprecated. Use
JansiConsoleAppender, which talks toorg.jline.jansi.AnsiConsoledirectly, instead of<withJansi>true</withJansi>on a plainConsoleAppender.- Parameters:
withJansi- whether to use JANSI or not.- Since:
- 1.0.5
-
JansiConsoleAppenderinstead ofwithJansionConsoleAppender.