Class JsonTemplateLayout
- java.lang.Object
-
- org.apache.logging.log4j.layout.template.json.JsonTemplateLayout
-
- All Implemented Interfaces:
Layout<java.lang.String>,Encoder<LogEvent>,StringLayout
@Plugin(name="JsonTemplateLayout", category="Core", elementType="layout") public class JsonTemplateLayout extends java.lang.Object implements StringLayout
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJsonTemplateLayout.Builderprivate static classJsonTemplateLayout.Contextstatic classJsonTemplateLayout.EventTemplateAdditionalFieldprivate static classJsonTemplateLayout.StringBuilderEncoderStringBuilderEncoderclone replacing thread-local allocations with instance fields.
-
Field Summary
Fields Modifier and Type Field Description private java.nio.charset.Charsetcharsetprivate static java.util.Map<java.lang.String,java.lang.String>CONTENT_FORMATprivate java.lang.StringcontentTypeprivate Recycler<JsonTemplateLayout.Context>contextRecyclerprivate java.lang.StringeventDelimiterprivate TemplateResolver<LogEvent>eventResolver-
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
-
Constructor Summary
Constructors Modifier Constructor Description privateJsonTemplateLayout(JsonTemplateLayout.Builder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Recycler<JsonTemplateLayout.Context>createContextRecycler(JsonTemplateLayout.Builder builder, JsonWriter jsonWriter)private static java.util.function.Supplier<JsonTemplateLayout.Context>createContextSupplier(java.nio.charset.Charset charset, JsonWriter jsonWriter)private TemplateResolver<LogEvent>createEventResolver(JsonTemplateLayout.Builder builder, Configuration configuration, java.nio.charset.Charset charset, JsonWriter jsonWriter)voidencode(LogEvent event, ByteBufferDestination destination)Encodes the specified source object to some binary representation and writes the result to the specified destination.java.nio.charset.CharsetgetCharset()Gets the Charset this layout uses to encode Strings into bytes.java.util.Map<java.lang.String,java.lang.String>getContentFormat()Returns a description of the content format.java.lang.StringgetContentType()Returns the content type output by this layout.byte[]getFooter()Returns the format for the layout format.byte[]getHeader()Returns the header for the layout format.static JsonTemplateLayout.BuildernewBuilder()private static java.lang.StringreadEventTemplate(JsonTemplateLayout.Builder builder)private static java.lang.StringreadStackTraceElementTemplate(JsonTemplateLayout.Builder builder)private static java.lang.StringreadTemplate(java.lang.String template, java.lang.String templateUri, java.nio.charset.Charset charset)byte[]toByteArray(LogEvent event)Formats the event suitable for display.java.lang.StringtoSerializable(LogEvent event)Formats the event as an Object that can be serialized.
-
-
-
Field Detail
-
CONTENT_FORMAT
private static final java.util.Map<java.lang.String,java.lang.String> CONTENT_FORMAT
-
charset
private final java.nio.charset.Charset charset
-
contentType
private final java.lang.String contentType
-
eventResolver
private final TemplateResolver<LogEvent> eventResolver
-
eventDelimiter
private final java.lang.String eventDelimiter
-
contextRecycler
private final Recycler<JsonTemplateLayout.Context> contextRecycler
-
-
Constructor Detail
-
JsonTemplateLayout
private JsonTemplateLayout(JsonTemplateLayout.Builder builder)
-
-
Method Detail
-
createEventResolver
private TemplateResolver<LogEvent> createEventResolver(JsonTemplateLayout.Builder builder, Configuration configuration, java.nio.charset.Charset charset, JsonWriter jsonWriter)
-
readEventTemplate
private static java.lang.String readEventTemplate(JsonTemplateLayout.Builder builder)
-
readStackTraceElementTemplate
private static java.lang.String readStackTraceElementTemplate(JsonTemplateLayout.Builder builder)
-
readTemplate
private static java.lang.String readTemplate(java.lang.String template, java.lang.String templateUri, java.nio.charset.Charset charset)
-
createContextRecycler
private static Recycler<JsonTemplateLayout.Context> createContextRecycler(JsonTemplateLayout.Builder builder, JsonWriter jsonWriter)
-
createContextSupplier
private static java.util.function.Supplier<JsonTemplateLayout.Context> createContextSupplier(java.nio.charset.Charset charset, JsonWriter jsonWriter)
-
toByteArray
public byte[] toByteArray(LogEvent event)
Description copied from interface:LayoutFormats the event suitable for display.- Specified by:
toByteArrayin interfaceLayout<java.lang.String>- Parameters:
event- The Logging Event.- Returns:
- The formatted event.
-
toSerializable
public java.lang.String toSerializable(LogEvent event)
Description copied from interface:LayoutFormats the event as an Object that can be serialized.- Specified by:
toSerializablein interfaceLayout<java.lang.String>- Parameters:
event- The Logging Event.- Returns:
- The formatted event.
-
encode
public void encode(LogEvent event, ByteBufferDestination destination)
Description copied from interface:EncoderEncodes the specified source object to some binary representation and writes the result to the specified destination.
-
getFooter
public byte[] getFooter()
Description copied from interface:LayoutReturns the format for the layout format.
-
getHeader
public byte[] getHeader()
Description copied from interface:LayoutReturns the header for the layout format.
-
getCharset
public java.nio.charset.Charset getCharset()
Description copied from interface:StringLayoutGets the Charset this layout uses to encode Strings into bytes.- Specified by:
getCharsetin interfaceStringLayout- Returns:
- the Charset this layout uses to encode Strings into bytes.
-
getContentType
public java.lang.String getContentType()
Description copied from interface:LayoutReturns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentTypein interfaceLayout<java.lang.String>- Returns:
- the content type.
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
Description copied from interface:LayoutReturns a description of the content format.- Specified by:
getContentFormatin interfaceLayout<java.lang.String>- Returns:
- a Map of key/value pairs describing the Layout-specific content format, or an empty Map if no content format descriptors are specified.
-
newBuilder
@PluginBuilderFactory public static JsonTemplateLayout.Builder newBuilder()
-
-