org.apache.logging.log4j.core
Interface Layout<T extends Serializable>

Type Parameters:
T - The Object type that will be returned on the toSerializable(LogEvent) call.
All Known Implementing Classes:
AbstractLayout, AbstractStringLayout, HTMLLayout, PatternLayout, RFC5424Layout, SerializedLayout, SyslogLayout, XMLLayout

public interface Layout<T extends Serializable>

Lays out a LogEvent in different formats. The formats are: byte[], or an implementor of Serializable, like byte[], String, and LogEvent.

Troublesome:
There is still a need for a character-based layout for character based event sinks (databases, etc). Would introduce an EventEncoder, EventRenderer or something similar for the logging event to byte encoding. (RG) A layout can be configured with a Charset and then Strings can be converted to byte arrays. OTOH, it isn't possible to write byte arrays as character streams.

Method Summary
 byte[] getFooter()
          Returns the format for the layout format.
 byte[] getHeader()
          Returns the header for the layout format.
 byte[] toByteArray(LogEvent event)
          Formats the event suitable for display.
 T toSerializable(LogEvent event)
          Formats the event as an Object that can be serialized.
 

Method Detail

getFooter

byte[] getFooter()
Returns the format for the layout format.

Returns:
The footer.
Troublesome:
the concept of header and footer is not universal, should not be on the base interface. (RG) I agree with this.

getHeader

byte[] getHeader()
Returns the header for the layout format.

Returns:
The header.
Troublesome:
the concept of header and footer is not universal, should not be on the base interface. (RG) I agree with this.

toByteArray

byte[] toByteArray(LogEvent event)
Formats the event suitable for display.

Parameters:
event - The Logging Event.
Returns:
The formatted event.
Troublesome:
Likely better to write to a OutputStream instead of return a byte[]. (RG) That limits how the Appender can use the Layout. For example, it might concatenate information in front or behind the data and then write it all to the OutputStream in one call.

toSerializable

T toSerializable(LogEvent event)
Formats the event as an Object that can be serialized.

Parameters:
event - The Logging Event.
Returns:
The formatted event.


Copyright © 1999-2012 Apache Software Foundation. All Rights Reserved. Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.