Class Rfc5424Layout
java.lang.Object
org.apache.logging.log4j.core.layout.AbstractLayout<String>
org.apache.logging.log4j.core.layout.AbstractStringLayout
org.apache.logging.log4j.core.layout.Rfc5424Layout
- All Implemented Interfaces:
LocationAware
,Layout<String>
,Encoder<LogEvent>
,StringLayout
@Plugin(name="Rfc5424Layout",
category="Core",
elementType="layout",
printObject=true)
public final class Rfc5424Layout
extends AbstractStringLayout
Formats a log event in accordance with RFC 5424.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
static class
private class
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Builder<B extends AbstractStringLayout.Builder<B>>, AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
private static final String
private final String
static final int
The default example enterprise number from RFC5424.static final String
The default event id.static final String
Default MDC ID: "mdc" .private final String
static final Pattern
For now, avoid too restrictive OID checks to allow for easier transitionprivate final String
private final String
private final String
private final List
<PatternFormatter> private final Facility
private final Map
<String, Rfc5424Layout.FieldFormatter> private final boolean
private final boolean
private long
private static final String
private final ListChecker
private final String
private final String
private final String
private final StructuredDataId
private final String
private static final int
private static final int
static final Pattern
Match newlines in a platform-independent manner.static final Pattern
Deprecated.private final String
private static final int
private String
private static final int
private final boolean
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGER
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Rfc5424Layout
(Configuration config, Facility facility, String id, String ein, boolean includeMDC, boolean includeNL, String escapeNL, String mdcId, String mdcPrefix, String eventPrefix, String appName, String messageId, String excludes, String includes, String required, Charset charset, String exceptionPattern, boolean useTLSMessageFormat, LoggerFields[] loggerFields) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addStructuredData
(Map<String, Rfc5424Layout.StructuredDataElement> sdElements, StructuredDataMessage data) private void
appendAppName
(StringBuilder buffer) private void
appendHostName
(StringBuilder buffer) private void
appendMap
(String prefix, Map<String, String> map, StringBuilder sb, ListChecker checker) private void
appendMessage
(StringBuilder buffer, LogEvent event) private void
appendMessageId
(StringBuilder buffer, Message message) private void
appendPriority
(StringBuilder buffer, Level logLevel) private void
appendProcessId
(StringBuilder buffer) private void
appendSpace
(StringBuilder buffer) private void
appendStructuredElements
(StringBuilder buffer, LogEvent event) private void
appendTimestamp
(StringBuilder buffer, long milliseconds) private void
checkRequired
(Map<String, String> map) private String
computeTimeStampString
(long now) private Map
<String, Rfc5424Layout.FieldFormatter> createFieldFormatters
(LoggerFields[] loggerFields, Configuration config) static Rfc5424Layout
createLayout
(Facility facility, String id, int enterpriseNumber, boolean includeMDC, String mdcId, String mdcPrefix, String eventPrefix, boolean newLine, String escapeNL, String appName, String msgId, String excludes, String includes, String required, String exceptionPattern, boolean useTlsMessageFormat, LoggerFields[] loggerFields, Configuration config) Deprecated.private static PatternParser
createPatternParser
(Configuration config, Class<? extends PatternConverter> filterClass) Create a PatternParser.private String
escapeNewlines
(String text, String replacement) private String
escapeSDParams
(String value) private void
formatStructuredElement
(String id, Rfc5424Layout.StructuredDataElement data, StringBuilder sb, ListChecker checker) Gets this Rfc5424Layout's content format.private String
getMdcId()
protected String
boolean
private void
pad
(int val, int max, StringBuilder buf) toSerializable
(LogEvent event) Formats aLogEvent
in conformance with the RFC 5424 Syslog specification.toString()
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getContentType, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, requiresLocation, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
encode, getConfiguration, markEvent
-
Field Details
-
DEFAULT_ENTERPRISE_NUMBER
public static final int DEFAULT_ENTERPRISE_NUMBERThe default example enterprise number from RFC5424.- See Also:
-
DEFAULT_ID
The default event id.- See Also:
-
NEWLINE_PATTERN
Match newlines in a platform-independent manner. -
PARAM_VALUE_ESCAPE_PATTERN
Deprecated.Match characters which require escaping. -
ENTERPRISE_ID_PATTERN
For now, avoid too restrictive OID checks to allow for easier transition -
DEFAULT_MDCID
Default MDC ID: "mdc" .- See Also:
-
LF
- See Also:
-
TWO_DIGITS
private static final int TWO_DIGITS- See Also:
-
THREE_DIGITS
private static final int THREE_DIGITS- See Also:
-
MILLIS_PER_MINUTE
private static final int MILLIS_PER_MINUTE- See Also:
-
MINUTES_PER_HOUR
private static final int MINUTES_PER_HOUR- See Also:
-
COMPONENT_KEY
- See Also:
-
facility
-
defaultId
-
enterpriseNumber
-
includeMdc
private final boolean includeMdc -
mdcId
-
mdcSdId
-
localHostName
-
appName
-
messageId
-
configName
-
mdcPrefix
-
eventPrefix
-
mdcExcludes
-
mdcIncludes
-
mdcRequired
-
listChecker
-
includeNewLine
private final boolean includeNewLine -
escapeNewLine
-
useTlsMessageFormat
private final boolean useTlsMessageFormat -
lastTimestamp
private long lastTimestamp -
timestamppStr
-
exceptionFormatters
-
fieldFormatters
-
procId
-
-
Constructor Details
-
Rfc5424Layout
private Rfc5424Layout(Configuration config, Facility facility, String id, String ein, boolean includeMDC, boolean includeNL, String escapeNL, String mdcId, String mdcPrefix, String eventPrefix, String appName, String messageId, String excludes, String includes, String required, Charset charset, String exceptionPattern, boolean useTLSMessageFormat, LoggerFields[] loggerFields)
-
-
Method Details
-
createFieldFormatters
private Map<String,Rfc5424Layout.FieldFormatter> createFieldFormatters(LoggerFields[] loggerFields, Configuration config) -
createPatternParser
private static PatternParser createPatternParser(Configuration config, Class<? extends PatternConverter> filterClass) Create a PatternParser.- Parameters:
config
- The Configuration.filterClass
- Filter the returned plugins after calling the plugin manager.- Returns:
- The PatternParser.
-
getContentFormat
Gets this Rfc5424Layout's content format. Specified by:- Key: "structured" Value: "true"
- Key: "format" Value: "RFC5424"
- Specified by:
getContentFormat
in interfaceLayout<String>
- Overrides:
getContentFormat
in classAbstractLayout<String>
- Returns:
- Map of content format keys supporting Rfc5424Layout
-
toSerializable
Formats aLogEvent
in conformance with the RFC 5424 Syslog specification.- Parameters:
event
- The LogEvent.- Returns:
- The RFC 5424 String representation of the LogEvent.
-
appendPriority
-
appendTimestamp
-
appendSpace
-
appendHostName
-
appendAppName
-
appendProcessId
-
appendMessageId
-
appendMessage
-
appendStructuredElements
-
addStructuredData
private void addStructuredData(Map<String, Rfc5424Layout.StructuredDataElement> sdElements, StructuredDataMessage data) -
escapeNewlines
-
getProcId
-
getMdcExcludes
-
getMdcIncludes
-
computeTimeStampString
-
pad
-
formatStructuredElement
private void formatStructuredElement(String id, Rfc5424Layout.StructuredDataElement data, StringBuilder sb, ListChecker checker) -
getId
-
checkRequired
-
appendMap
private void appendMap(String prefix, Map<String, String> map, StringBuilder sb, ListChecker checker) -
escapeSDParams
-
toString
-
createLayout
@PluginFactory public static Rfc5424Layout createLayout(@PluginAttribute(value="facility",defaultString="LOCAL0") Facility facility, @PluginAttribute("id") String id, @PluginAttribute(value="enterpriseNumber",defaultInt=32473) int enterpriseNumber, @PluginAttribute(value="includeMDC",defaultBoolean=true) boolean includeMDC, @PluginAttribute(value="mdcId",defaultString="mdc") String mdcId, @PluginAttribute("mdcPrefix") String mdcPrefix, @PluginAttribute("eventPrefix") String eventPrefix, @PluginAttribute("newLine") boolean newLine, @PluginAttribute("newLineEscape") String escapeNL, @PluginAttribute("appName") String appName, @PluginAttribute("messageId") String msgId, @PluginAttribute("mdcExcludes") String excludes, @PluginAttribute("mdcIncludes") String includes, @PluginAttribute("mdcRequired") String required, @PluginAttribute("exceptionPattern") String exceptionPattern, @PluginAttribute("useTlsMessageFormat") boolean useTlsMessageFormat, @PluginElement("LoggerFields") LoggerFields[] loggerFields, @PluginConfiguration Configuration config) Deprecated.Useinstead
Create the RFC 5424 Layout.- Parameters:
facility
- The Facility is used to try to classify the message.id
- The default structured data id to use when formatting according to RFC 5424.enterpriseNumber
- The IANA enterprise number.includeMDC
- Indicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog record. Defaults to "true:.mdcId
- The id to use for the MDC Structured Data Element.mdcPrefix
- The prefix to add to MDC key names.eventPrefix
- The prefix to add to event key names.newLine
- If true, a newline will be appended to the end of the syslog record. The default is false.escapeNL
- String that should be used to replace newlines within the message text.appName
- The value to use as the APP-NAME in the RFC 5424 syslog record.msgId
- The default value to be used in the MSGID field of RFC 5424 syslog records.excludes
- A comma separated list of MDC keys that should be excluded from the LogEvent.includes
- A comma separated list of MDC keys that should be included in the FlumeEvent.required
- A comma separated list of MDC keys that must be present in the MDC.exceptionPattern
- The pattern for formatting exceptions.useTlsMessageFormat
- If true the message will be formatted according to RFC 5425.loggerFields
- Container for the KeyValuePairs containing the patternsconfig
- The Configuration. Some Converters require access to the Interpolator.- Returns:
- An Rfc5424Layout.
-
getFacility
-
getDefaultId
-
getEnterpriseNumber
-
isIncludeMdc
public boolean isIncludeMdc() -
getMdcId
-
instead