Class WriterManager
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.AbstractManager
-
- org.apache.logging.log4j.core.appender.WriterManager
-
- All Implemented Interfaces:
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringLayout
layout
-
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
-
Constructor Summary
Constructors Constructor Description WriterManager(Writer writer, String streamName, StringLayout layout, boolean writeHeader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeWriter()
void
flush()
Flushes any buffers.static <T> WriterManager
getManager(String name, T data, ManagerFactory<? extends WriterManager,T> factory)
Creates a Manager.protected Writer
getWriter()
boolean
isOpen()
Returns the status of the stream.boolean
releaseSub(long timeout, TimeUnit timeUnit)
Default hook to write footer during close.protected void
setWriter(Writer writer)
protected void
write(String str)
Some output streams synchronize writes while others do not.protected void
writeFooter()
Writes the footer.-
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
-
-
-
Field Detail
-
layout
protected final StringLayout layout
-
-
Constructor Detail
-
WriterManager
public WriterManager(Writer writer, String streamName, StringLayout layout, boolean writeHeader)
-
-
Method Detail
-
getManager
public static <T> WriterManager getManager(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 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, TimeUnit timeUnit)
Default hook to write footer during close.- Overrides:
releaseSub
in classAbstractManager
- Parameters:
timeout
- timeouttimeUnit
- timeout time unit- Returns:
- true if all resources were closed normally, false otherwise.
-
setWriter
protected void setWriter(Writer writer)
-
write
protected void write(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.
-
-