Class WriterManager
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.AbstractManager
-
- org.apache.logging.log4j.core.appender.WriterManager
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class WriterManager extends AbstractManager
Manages a Writer so that it can be shared by multiple Appenders and will allow appenders to reconfigure without requiring a new writer.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData
-
-
Field Summary
Fields Modifier and Type Field Description protected StringLayoutlayoutprivate java.io.Writerwriter-
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
-
Constructor Summary
Constructors Constructor Description WriterManager(java.io.Writer writer, java.lang.String streamName, StringLayout layout, boolean writeHeader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseWriter()voidflush()Flushes any buffers.static <T> WriterManagergetManager(java.lang.String name, T data, ManagerFactory<? extends WriterManager,T> factory)Creates a Manager.protected java.io.WritergetWriter()booleanisOpen()Returns the status of the stream.booleanreleaseSub(long timeout, java.util.concurrent.TimeUnit timeUnit)Default hook to write footer during close.protected voidsetWriter(java.io.Writer writer)protected voidwrite(java.lang.String str)Some output streams synchronize writes while others do not.protected voidwriteFooter()Writes the footer.-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getManagerCount, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
-
-
-
Field Detail
-
layout
protected final StringLayout layout
-
writer
private volatile java.io.Writer writer
-
-
Constructor Detail
-
WriterManager
public WriterManager(java.io.Writer writer, java.lang.String streamName, StringLayout layout, boolean writeHeader)
-
-
Method Detail
-
getManager
public static <T> WriterManager getManager(java.lang.String name, T data, ManagerFactory<? extends WriterManager,T> factory)
Creates a Manager.- Type Parameters:
T- The type of the WriterManager.- Parameters:
name- The name of the stream to manage.data- The data to pass to the Manager.factory- The factory to use to create the Manager.- Returns:
- A WriterManager.
-
closeWriter
protected void closeWriter()
-
flush
public void flush()
Flushes any buffers.
-
getWriter
protected java.io.Writer getWriter()
-
isOpen
public boolean isOpen()
Returns the status of the stream.- Returns:
- true if the stream is open, false if it is not.
-
releaseSub
public boolean releaseSub(long timeout, java.util.concurrent.TimeUnit timeUnit)Default hook to write footer during close.- Overrides:
releaseSubin classAbstractManager- Parameters:
timeout- timeouttimeUnit- timeout time unit- Returns:
- true if all resources were closed normally, false otherwise.
-
setWriter
protected void setWriter(java.io.Writer writer)
-
write
protected void write(java.lang.String str)
Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Parameters:
str- the string to write- Throws:
AppenderLoggingException- if an error occurs.
-
writeFooter
protected void writeFooter()
Writes the footer.
-
-