Class JsonTemplateLayout
java.lang.Object
org.apache.logging.log4j.layout.template.json.JsonTemplateLayout
- All Implemented Interfaces:
Layout<String>
,Encoder<LogEvent>
,StringLayout
@Plugin(name="JsonTemplateLayout",
category="Core",
elementType="layout")
public class JsonTemplateLayout
extends Object
implements StringLayout
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
(package private) static final class
static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Charset
private final String
private final Recycler
<JsonTemplateLayout.Context> private final String
private final TemplateResolver
<LogEvent> Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) JsonTemplateLayout.Context
private static Recycler
<JsonTemplateLayout.Context> createContextRecycler
(JsonTemplateLayout.Builder builder, JsonWriter jsonWriter) private static Supplier
<JsonTemplateLayout.Context> createContextSupplier
(Charset charset, JsonWriter jsonWriter) private TemplateResolver
<LogEvent> createEventResolver
(JsonTemplateLayout.Builder builder, Configuration configuration, Charset charset, JsonWriter jsonWriter) private static Encoder
<StringBuilder> createStringBuilderEncoder
(Charset charset) void
encode
(LogEvent event, ByteBufferDestination destination) Encodes the specified source object to some binary representation and writes the result to the specified destination.Gets the Charset this layout uses to encode Strings into bytes.Returns a description of the content format.Returns the content type output by this layout.byte[]
Returns the format for the layout format.byte[]
Returns the header for the layout format.static JsonTemplateLayout.Builder
private static String
private static String
private static String
readTemplate
(String template, String templateUri, Charset charset) byte[]
toByteArray
(LogEvent event) Formats the event suitable for display.toSerializable
(LogEvent event) Formats the event as an Object that can be serialized.
-
Field Details
-
CONTENT_FORMAT
-
charset
-
contentType
-
eventResolver
-
eventDelimiter
-
contextRecycler
-
-
Constructor Details
-
JsonTemplateLayout
-
-
Method Details
-
createEventResolver
private TemplateResolver<LogEvent> createEventResolver(JsonTemplateLayout.Builder builder, Configuration configuration, Charset charset, JsonWriter jsonWriter) -
readEventTemplate
-
readStackTraceElementTemplate
-
readTemplate
-
createContextRecycler
private static Recycler<JsonTemplateLayout.Context> createContextRecycler(JsonTemplateLayout.Builder builder, JsonWriter jsonWriter) -
createContextSupplier
private static Supplier<JsonTemplateLayout.Context> createContextSupplier(Charset charset, JsonWriter jsonWriter) -
createStringBuilderEncoder
-
toByteArray
Description copied from interface:Layout
Formats the event suitable for display.- Specified by:
toByteArray
in interfaceLayout<String>
- Parameters:
event
- The Logging Event.- Returns:
- The formatted event.
-
toSerializable
Description copied from interface:Layout
Formats the event as an Object that can be serialized.- Specified by:
toSerializable
in interfaceLayout<String>
- Parameters:
event
- The Logging Event.- Returns:
- The formatted event.
-
encode
Description copied from interface:Encoder
Encodes the specified source object to some binary representation and writes the result to the specified destination. -
acquireContext
JsonTemplateLayout.Context acquireContext() -
getHeader
public byte[] getHeader()Description copied from interface:Layout
Returns the header for the layout format. -
getCharset
Description copied from interface:StringLayout
Gets the Charset this layout uses to encode Strings into bytes.- Specified by:
getCharset
in interfaceStringLayout
- Returns:
- the Charset this layout uses to encode Strings into bytes.
-
getContentType
Description copied from interface:Layout
Returns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentType
in interfaceLayout<String>
- Returns:
- the content type.
-
getContentFormat
Description copied from interface:Layout
Returns a description of the content format.- Specified by:
getContentFormat
in interfaceLayout<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
-