Class OutputStreamManager
- All Implemented Interfaces:
AutoCloseable
,ByteBufferDestination
- Direct Known Subclasses:
AbstractSocketManager
,FileManager
,MemoryMappedFileManager
,RandomAccessFileManager
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData
-
Field Summary
Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER
-
Constructor Summary
ModifierConstructorDescriptionprotected
OutputStreamManager
(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader) protected
OutputStreamManager
(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, int bufferSize) protected
OutputStreamManager
(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, ByteBuffer byteBuffer) Deprecated.protected
OutputStreamManager
(LoggerContext loggerContext, OutputStream os, String streamName, boolean createOnDemand, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer byteBuffer) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
protected OutputStream
drain
(ByteBuffer buf) Drains the ByteBufferDestination's buffer into the destination.void
flush()
Flushes any buffers.protected void
flushBuffer
(ByteBuffer buf) Drains the ByteBufferDestination's buffer into the destination.protected void
Callsflush()
on the underlying output stream.Returns thisByteBufferDestination
's buffer.static <T> OutputStreamManager
getManager
(String name, T data, ManagerFactory<? extends OutputStreamManager, T> factory) Creates a Manager.protected OutputStream
boolean
boolean
isOpen()
Returns the status of the stream.boolean
releaseSub
(long timeout, TimeUnit timeUnit) Default hook to write footer during close.protected void
void
skipFooter
(boolean skipFooter) Indicate whether the footer should be skipped or not.protected void
write
(byte[] bytes) Some output streams synchronize writes while others do not.protected void
write
(byte[] bytes, boolean immediateFlush) Some output streams synchronize writes while others do not.protected void
write
(byte[] bytes, int offset, int length) Some output streams synchronize writes while others do not.protected void
write
(byte[] bytes, int offset, int length, boolean immediateFlush) Some output streams synchronize writes while others do not.void
writeBytes
(byte[] data, int offset, int length) Writes the given data to this ByteBufferDestination.void
writeBytes
(ByteBuffer data) Writes the given data to this ByteBufferDestination entirely.protected void
Writes the footer.protected void
protected void
writeToDestination
(byte[] bytes, int offset, int length) Writes the specified section of the specified byte array to the stream.Methods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getContentFormat, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
Field Details
-
layout
-
byteBuffer
-
-
Constructor Details
-
OutputStreamManager
protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader) -
OutputStreamManager
protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, int bufferSize) -
OutputStreamManager
@Deprecated protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, ByteBuffer byteBuffer) Deprecated.- Since:
- 2.6
-
OutputStreamManager
protected OutputStreamManager(LoggerContext loggerContext, OutputStream os, String streamName, boolean createOnDemand, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer byteBuffer) - Since:
- 2.7
-
-
Method Details
-
getManager
public static <T> OutputStreamManager getManager(String name, T data, ManagerFactory<? extends OutputStreamManager, T> factory) Creates a Manager.- Type Parameters:
T
- The type of the OutputStreamManager.- 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:
- An OutputStreamManager.
-
createOutputStream
- Throws:
IOException
-
releaseSub
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.
-
writeHeader
-
isOpen
public boolean isOpen()Returns the status of the stream.- Returns:
- true if the stream is open, false if it is not.
-
hasOutputStream
public boolean hasOutputStream() -
getOutputStream
- Throws:
IOException
-
setOutputStream
-
write
protected void write(byte[] bytes) Some output streams synchronize writes while others do not.- Parameters:
bytes
- The serialized Log event.- Throws:
AppenderLoggingException
- if an error occurs.
-
write
protected void write(byte[] bytes, boolean immediateFlush) Some output streams synchronize writes while others do not.- Parameters:
bytes
- The serialized Log event.immediateFlush
- If true, flushes after writing.- Throws:
AppenderLoggingException
- if an error occurs.
-
writeBytes
public void writeBytes(byte[] data, int offset, int length) Description copied from interface:ByteBufferDestination
Writes the given data to this ByteBufferDestination. Call of this method should *not* be protected with synchronized on this ByteBufferDestination instance. ByteBufferDestination implementations should synchronize themselves inside this method, if needed.This method should behave identically to
writeBytes(ByteBuffer.wrap(data, offset, length)
. It is provided to allow callers not to generate extra garbage.This method is called writeBytes() to avoid clashing with
write(byte[], int, int)
, which might be overridden in user-defined subclasses as protected, hence adding it to interface and requiring the method to be public breaks source compatibility.- Specified by:
writeBytes
in interfaceByteBufferDestination
-
write
protected void write(byte[] bytes, int offset, int length) Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Parameters:
bytes
- The serialized Log event.offset
- The offset into the byte array.length
- The number of bytes to write.- Throws:
AppenderLoggingException
- if an error occurs.
-
write
protected void write(byte[] bytes, int offset, int length, boolean immediateFlush) Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Parameters:
bytes
- The serialized Log event.offset
- The offset into the byte array.length
- The number of bytes to write.immediateFlush
- flushes immediately after writing.- Throws:
AppenderLoggingException
- if an error occurs.
-
writeToDestination
protected void writeToDestination(byte[] bytes, int offset, int length) Writes the specified section of the specified byte array to the stream.- Parameters:
bytes
- the array containing dataoffset
- from where to writelength
- how many bytes to write- Since:
- 2.6
-
flushDestination
protected void flushDestination()Callsflush()
on the underlying output stream.- Since:
- 2.6
-
flushBuffer
Drains the ByteBufferDestination's buffer into the destination. By default this callswrite(byte[], int, int, boolean)
with the buffer contents. The underlying stream is not flushed.- Since:
- 2.6
- See Also:
-
flush
public void flush()Flushes any buffers. -
closeOutputStream
protected boolean closeOutputStream() -
getByteBuffer
Returns thisByteBufferDestination
's buffer.- Specified by:
getByteBuffer
in interfaceByteBufferDestination
- Returns:
- the buffer
- Since:
- 2.6
-
drain
Drains the ByteBufferDestination's buffer into the destination. By default this callsflushBuffer(ByteBuffer)
with the specified buffer. Subclasses may override.Do not call this method lightly! For some subclasses this is a very expensive operation. For example,
MemoryMappedFileManager
will assume this method was called because the end of the mapped region was reached during a text encoding operation and will remap its buffer.To just flush the buffered contents to the underlying stream, call
flushBuffer(ByteBuffer)
directly instead.- Specified by:
drain
in interfaceByteBufferDestination
- Parameters:
buf
- the buffer whose contents to write the destination- Returns:
- the specified buffer
- Since:
- 2.6
-
writeBytes
Description copied from interface:ByteBufferDestination
Writes the given data to this ByteBufferDestination entirely. Call of this method should *not* be protected with synchronized on this ByteBufferDestination instance. ByteBufferDestination implementations should synchronize themselves inside this method, if needed.- Specified by:
writeBytes
in interfaceByteBufferDestination
-