- 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>
-
- All Implemented Interfaces:
Appender<E>,ContextAware,FilterAttachable<E>,LifeCycle
- Direct Known Subclasses:
JansiConsoleAppender
public class ConsoleAppender<E> extends OutputStreamAppender<E>
ConsoleAppender appends log events toSystem.outorSystem.errusing a layout specified by the user. The default target isSystem.out.
For more information about this appender, please refer to the online manual at http://logback.qos.ch/manual/appenders.html#ConsoleAppenderThis 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:
- logback issue #1063
-
-
Field Summary
Fields Modifier and Type Field Description static StringFUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAMEstatic StringJLINE_JANSI_ANSI_CONSOLE_CLASS_NAMEprotected StringpreferredJansiClassNameprotected ConsoleTargettargetprotected booleanwithJansi-
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 ConsoleAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected ReentryGuardbuildReentryGuard()Create a ThreadLocal ReentryGuard to prevent recursive appender invocations.protected voidcloseOutputStream()Flush the console target without closing it.StringgetPreferredJansiClassName()StringgetTarget()Returns the current value of the target property.booleanisWithJansi()Deprecated.voidsetPreferredJansiClassName(String preferredJansiClassName)It allows to force Jansi class name used for probing.voidsetTarget(String value)Sets 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, 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
-
-
-
-
Field Detail
-
target
protected ConsoleTarget target
-
withJansi
protected boolean withJansi
-
JLINE_JANSI_ANSI_CONSOLE_CLASS_NAME
public static final String JLINE_JANSI_ANSI_CONSOLE_CLASS_NAME
- See Also:
- Constant Field Values
-
FUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAME
public static final String FUSESOURCE_JANSI_ANSI_CONSOLE_CLASS_NAME
- See Also:
- Constant Field Values
-
preferredJansiClassName
protected String preferredJansiClassName
-
-
Constructor Detail
-
ConsoleAppender
public ConsoleAppender()
-
-
Method Detail
-
setTarget
public void setTarget(String value)
Sets the value of the Target option. Recognized values are "System.out" and "System.err". Any other value will be ignored.
-
getTarget
public String 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
public String getPreferredJansiClassName()
- Returns:
- the preferred Jansi class name
-
setPreferredJansiClassName
public void setPreferredJansiClassName(String preferredJansiClassName)
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
public void 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
protected void 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
protected ReentryGuard buildReentryGuard()
Create a ThreadLocal ReentryGuard to prevent recursive appender invocations.- Overrides:
buildReentryGuardin classUnsynchronizedAppenderBase<E>- Returns:
- a ReentryGuard instance of type
THREAD_LOCAL.
-
wrapTarget
protected OutputStream wrapTarget(OutputStream targetStream)
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 protected OutputStream wrapWithJansi(OutputStream targetStream)
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 public boolean isWithJansi()
Deprecated.- Returns:
- whether to use JANSI or not.
-
setWithJansi
@Deprecated public void setWithJansi(boolean withJansi)
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
-
-