T
- The Class that the Layout will format the LogEvent into.public abstract class AbstractLayout<T extends Serializable> extends Object implements Layout<T>
Modifier and Type | Class and Description |
---|---|
static class |
AbstractLayout.Builder<B extends AbstractLayout.Builder<B>>
Subclasses can extend this abstract Builder.
|
Modifier and Type | Field and Description |
---|---|
protected Configuration |
configuration
The current Configuration.
|
protected long |
eventCount
The number of events successfully processed by this layout.
|
protected byte[] |
footer
The footer to add when the stream is closed.
|
protected byte[] |
header
The header to include when the stream is opened.
|
protected static Logger |
LOGGER
Allow subclasses access to the status logger without creating another instance.
|
ELEMENT_TYPE
Constructor and Description |
---|
AbstractLayout(byte[] header,
byte[] footer)
Deprecated.
|
AbstractLayout(Configuration configuration,
byte[] header,
byte[] footer)
Constructs a layout with an optional header and footer.
|
Modifier and Type | Method and Description |
---|---|
void |
encode(LogEvent event,
ByteBufferDestination destination)
Encodes the specified source LogEvent to some binary representation and writes the result to the specified
destination.
|
Configuration |
getConfiguration() |
Map<String,String> |
getContentFormat()
Returns a description of the content format.
|
byte[] |
getFooter()
Returns the footer, if one is available.
|
byte[] |
getHeader()
Returns the header, if one is available.
|
protected void |
markEvent() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getContentType, toByteArray, toSerializable
protected static final Logger LOGGER
protected final Configuration configuration
protected long eventCount
protected final byte[] footer
protected final byte[] header
@Deprecated public AbstractLayout(byte[] header, byte[] footer)
AbstractLayout(Configuration, byte[], byte[])
header
- The header to include when the stream is opened. May be null.footer
- The footer to add when the stream is closed. May be null.public AbstractLayout(Configuration configuration, byte[] header, byte[] footer)
configuration
- The configuration. May be null.header
- The header to include when the stream is opened. May be null.footer
- The footer to add when the stream is closed. May be null.public Configuration getConfiguration()
public Map<String,String> getContentFormat()
Layout
getContentFormat
in interface Layout<T extends Serializable>
public byte[] getFooter()
getFooter
in interface Layout<T extends Serializable>
public byte[] getHeader()
getHeader
in interface Layout<T extends Serializable>
protected void markEvent()
public void encode(LogEvent event, ByteBufferDestination destination)
The default implementation of this method delegates to the Layout.toByteArray(LogEvent)
method which allocates
temporary objects.
Subclasses can override this method to provide a garbage-free implementation. For text-based layouts,
AbstractStringLayout
provides various convenience methods to help with this:
@Plugin(name = "MyLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) public final class MyLayout extends AbstractStringLayout {
encode
in interface Encoder<LogEvent>
event
- the LogEvent to encode.destination
- holds the ByteBuffer to write into.AbstractStringLayout.getStringBuilder()
,
AbstractStringLayout.getStringBuilderEncoder()
Copyright © 1999-2023 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.