Class ESJsonLayout
- java.lang.Object
-
- org.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
- org.apache.logging.log4j.core.layout.AbstractStringLayout
-
- org.elasticsearch.common.logging.ESJsonLayout
-
- All Implemented Interfaces:
org.apache.logging.log4j.core.Layout<java.lang.String>,org.apache.logging.log4j.core.layout.Encoder<org.apache.logging.log4j.core.LogEvent>,org.apache.logging.log4j.core.StringLayout
@Plugin(name="ESJsonLayout", category="Core", elementType="layout", printObject=true) public class ESJsonLayout extends org.apache.logging.log4j.core.layout.AbstractStringLayoutFormats log events as strings in a json format.The class is wrapping the
PatternLayoutwith a pattern to format into json. This gives more flexibility and control over how the log messages are formatted inJsonLayoutThere are fields which are always present in the log line:- type - the type of logs. These represent appenders and help docker distinguish log streams.
- timestamp - ISO8601 with additional timezone ID
- level - INFO, WARN etc
- component - logger name, most of the times class name
- cluster.name - taken from sys:es.logs.cluster_name system property because it is always set
- node.name - taken from NodeNamePatternConverter, as it can be set in runtime as hostname when not set in elasticsearch.yml
- node_and_cluster_id - in json as node.id and cluster.uuid - taken from NodeAndClusterIdConverter and present once clusterStateUpdate is first received
- message - a json escaped message. Multiline messages will be converted to single line with new line explicitly replaced to \n
- exceptionAsJson - in json as a stacktrace field. Only present when throwable is passed as a parameter when using a logger. Taken from JsonThrowablePatternConverter
It is possible to add more or override them with
esmessagefieldappender.logger.layout.esmessagefields=message,took,took_millis,total_hits,types,stats,search_type,total_shards,source,idEach of these will be expanded into a json field with a value takenESLogMessagefield. In the example above... "message": %ESMessageField{message}, "took": %ESMessageField{took} ...the message passed to a logger will be overriden with a value from %ESMessageField{message}The value taken from %ESMessageField{message} has to be a simple escaped JSON value and is populated in subclasses of
ESLogMessage
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classESJsonLayout.Builder<B extends ESJsonLayout.Builder<B>>
-
Constructor Summary
Constructors Modifier Constructor Description protectedESJsonLayout(java.lang.String typeName, java.nio.charset.Charset charset, java.lang.String[] esmessagefields)
-
Method Summary
Modifier and Type Method Description static ESJsonLayoutcreateLayout(java.lang.String type, java.nio.charset.Charset charset, java.lang.String[] esmessagefields)voidencode(org.apache.logging.log4j.core.LogEvent event, org.apache.logging.log4j.core.layout.ByteBufferDestination destination)java.util.Map<java.lang.String,java.lang.String>getContentFormat()static <B extends ESJsonLayout.Builder<B>>
BnewBuilder()java.lang.StringtoSerializable(org.apache.logging.log4j.core.LogEvent event)java.lang.StringtoString()-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getContentType, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
-
-
-
-
Method Detail
-
createLayout
@PluginFactory public static ESJsonLayout createLayout(java.lang.String type, java.nio.charset.Charset charset, java.lang.String[] esmessagefields)
-
newBuilder
@PluginBuilderFactory public static <B extends ESJsonLayout.Builder<B>> B newBuilder()
-
toSerializable
public java.lang.String toSerializable(org.apache.logging.log4j.core.LogEvent event)
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
- Specified by:
getContentFormatin interfaceorg.apache.logging.log4j.core.Layout<java.lang.String>- Overrides:
getContentFormatin classorg.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
encode
public void encode(org.apache.logging.log4j.core.LogEvent event, org.apache.logging.log4j.core.layout.ByteBufferDestination destination)- Specified by:
encodein interfaceorg.apache.logging.log4j.core.layout.Encoder<org.apache.logging.log4j.core.LogEvent>- Overrides:
encodein classorg.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-