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 classstatic classprivate classNested 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 Stringprivate static final Stringprivate final Stringstatic final intThe default example enterprise number from RFC5424.static final StringThe default event id.static final StringDefault MDC ID: "mdc" .private final Stringstatic final PatternFor now, avoid too restrictive OID checks to allow for easier transitionprivate final Stringprivate final Stringprivate final Stringprivate final List<PatternFormatter> private final Facilityprivate final Map<String, Rfc5424Layout.FieldFormatter> private final booleanprivate final booleanprivate longprivate static final Stringprivate final ListCheckerprivate final Stringprivate final Stringprivate final Stringprivate final StructuredDataIdprivate final Stringprivate static final intprivate static final intstatic final PatternMatch newlines in a platform-independent manner.static final PatternDeprecated.private final Stringprivate static final intprivate Stringprivate static final intprivate final booleanFields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZEFields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGERFields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRfc5424Layout(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 voidaddStructuredData(Map<String, Rfc5424Layout.StructuredDataElement> sdElements, StructuredDataMessage data) private voidappendAppName(StringBuilder buffer) private voidappendHostName(StringBuilder buffer) private voidappendMap(String prefix, Map<String, String> map, StringBuilder sb, ListChecker checker) private voidappendMessage(StringBuilder buffer, LogEvent event) private voidappendMessageId(StringBuilder buffer, Message message) private voidappendPriority(StringBuilder buffer, Level logLevel) private voidappendProcessId(StringBuilder buffer) private voidappendSpace(StringBuilder buffer) private voidappendStructuredElements(StringBuilder buffer, LogEvent event) private voidappendTimestamp(StringBuilder buffer, long milliseconds) private voidcheckRequired(Map<String, String> map) private StringcomputeTimeStampString(long now) private Map<String, Rfc5424Layout.FieldFormatter> createFieldFormatters(LoggerFields[] loggerFields, Configuration config) static Rfc5424LayoutcreateLayout(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 PatternParsercreatePatternParser(Configuration config, Class<? extends PatternConverter> filterClass) Create a PatternParser.private StringescapeNewlines(String text, String replacement) private StringescapeSDParams(String value) private voidformatStructuredElement(String id, Rfc5424Layout.StructuredDataElement data, StringBuilder sb, ListChecker checker) Gets this Rfc5424Layout's content format.private StringgetMdcId()protected Stringbooleanprivate voidpad(int val, int max, StringBuilder buf) toSerializable(LogEvent event) Formats aLogEventin 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, trimToMaxSizeMethods 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:
getContentFormatin interfaceLayout<String>- Overrides:
getContentFormatin classAbstractLayout<String>- Returns:
- Map of content format keys supporting Rfc5424Layout
-
toSerializable
Formats aLogEventin 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.UseinsteadCreate 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