Class Rfc5424Layout
- java.lang.Object
-
- org.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
- org.apache.logging.log4j.core.layout.AbstractStringLayout
-
- org.apache.logging.log4j.core.layout.Rfc5424Layout
-
- All Implemented Interfaces:
LocationAware,Layout<java.lang.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:
- RFC 5424
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classRfc5424Layout.FieldFormatterstatic classRfc5424Layout.Rfc5424LayoutBuilderprivate classRfc5424Layout.StructuredDataElement-
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
Fields Modifier and Type Field Description private java.lang.StringappNameprivate static java.lang.StringCOMPONENT_KEYprivate java.lang.StringconfigNamestatic intDEFAULT_ENTERPRISE_NUMBERThe default example enterprise number from RFC5424.static java.lang.StringDEFAULT_IDThe default event id.static java.lang.StringDEFAULT_MDCIDDefault MDC ID: "mdc" .private java.lang.StringdefaultIdstatic java.util.regex.PatternENTERPRISE_ID_PATTERNFor now, avoid too restrictive OID checks to allow for easier transitionprivate java.lang.StringenterpriseNumberprivate java.lang.StringescapeNewLineprivate java.lang.StringeventPrefixprivate java.util.List<PatternFormatter>exceptionFormattersprivate Facilityfacilityprivate java.util.Map<java.lang.String,Rfc5424Layout.FieldFormatter>fieldFormattersprivate booleanincludeMdcprivate booleanincludeNewLineprivate longlastTimestampprivate static java.lang.StringLFprivate ListCheckerlistCheckerprivate java.lang.StringlocalHostNameprivate java.util.List<java.lang.String>mdcExcludesprivate java.lang.StringmdcIdprivate java.util.List<java.lang.String>mdcIncludesprivate java.lang.StringmdcPrefixprivate java.util.List<java.lang.String>mdcRequiredprivate StructuredDataIdmdcSdIdprivate java.lang.StringmessageIdprivate static intMILLIS_PER_MINUTEprivate static intMINUTES_PER_HOURstatic java.util.regex.PatternNEWLINE_PATTERNMatch newlines in a platform-independent manner.static java.util.regex.PatternPARAM_VALUE_ESCAPE_PATTERNDeprecated.private java.lang.StringprocIdprivate static intTHREE_DIGITSprivate java.lang.StringtimestamppStrprivate static intTWO_DIGITSprivate booleanuseTlsMessageFormat-
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
Constructors Modifier Constructor Description privateRfc5424Layout(Configuration config, Facility facility, java.lang.String id, java.lang.String ein, boolean includeMDC, boolean includeNL, java.lang.String escapeNL, java.lang.String mdcId, java.lang.String mdcPrefix, java.lang.String eventPrefix, java.lang.String appName, java.lang.String messageId, java.lang.String excludes, java.lang.String includes, java.lang.String required, java.nio.charset.Charset charset, java.lang.String exceptionPattern, boolean useTLSMessageFormat, LoggerFields[] loggerFields)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidaddStructuredData(java.util.Map<java.lang.String,Rfc5424Layout.StructuredDataElement> sdElements, StructuredDataMessage data)private voidappendAppName(java.lang.StringBuilder buffer)private voidappendHostName(java.lang.StringBuilder buffer)private voidappendMap(java.lang.String prefix, java.util.Map<java.lang.String,java.lang.String> map, java.lang.StringBuilder sb, ListChecker checker)private voidappendMessage(java.lang.StringBuilder buffer, LogEvent event)private voidappendMessageId(java.lang.StringBuilder buffer, Message message)private voidappendPriority(java.lang.StringBuilder buffer, Level logLevel)private voidappendProcessId(java.lang.StringBuilder buffer)private voidappendSpace(java.lang.StringBuilder buffer)private voidappendStructuredElements(java.lang.StringBuilder buffer, LogEvent event)private voidappendTimestamp(java.lang.StringBuilder buffer, long milliseconds)private voidcheckRequired(java.util.Map<java.lang.String,java.lang.String> map)private java.lang.StringcomputeTimeStampString(long now)private java.util.Map<java.lang.String,Rfc5424Layout.FieldFormatter>createFieldFormatters(LoggerFields[] loggerFields, Configuration config)static Rfc5424LayoutcreateLayout(Facility facility, java.lang.String id, int enterpriseNumber, boolean includeMDC, java.lang.String mdcId, java.lang.String mdcPrefix, java.lang.String eventPrefix, boolean newLine, java.lang.String escapeNL, java.lang.String appName, java.lang.String msgId, java.lang.String excludes, java.lang.String includes, java.lang.String required, java.lang.String exceptionPattern, boolean useTlsMessageFormat, LoggerFields[] loggerFields, Configuration config)Deprecated.Useinsteadprivate static PatternParsercreatePatternParser(Configuration config, java.lang.Class<? extends PatternConverter> filterClass)Create a PatternParser.private java.lang.StringescapeNewlines(java.lang.String text, java.lang.String replacement)private java.lang.StringescapeSDParams(java.lang.String value)private voidformatStructuredElement(java.lang.String id, Rfc5424Layout.StructuredDataElement data, java.lang.StringBuilder sb, ListChecker checker)java.util.Map<java.lang.String,java.lang.String>getContentFormat()Gets this Rfc5424Layout's content format.java.lang.StringgetDefaultId()java.lang.StringgetEnterpriseNumber()FacilitygetFacility()private java.lang.StringgetId(StructuredDataId id)protected java.util.List<java.lang.String>getMdcExcludes()java.lang.StringgetMdcId()protected java.util.List<java.lang.String>getMdcIncludes()protected java.lang.StringgetProcId()booleanisIncludeMdc()private voidpad(int val, int max, java.lang.StringBuilder buf)java.lang.StringtoSerializable(LogEvent event)Formats aLogEventin conformance with the RFC 5424 Syslog specification.java.lang.StringtoString()-
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 Detail
-
DEFAULT_ENTERPRISE_NUMBER
public static final int DEFAULT_ENTERPRISE_NUMBER
The default example enterprise number from RFC5424.- See Also:
- Constant Field Values
-
DEFAULT_ID
public static final java.lang.String DEFAULT_ID
The default event id.- See Also:
- Constant Field Values
-
NEWLINE_PATTERN
public static final java.util.regex.Pattern NEWLINE_PATTERN
Match newlines in a platform-independent manner.
-
PARAM_VALUE_ESCAPE_PATTERN
@Deprecated public static final java.util.regex.Pattern PARAM_VALUE_ESCAPE_PATTERN
Deprecated.Match characters which require escaping.
-
ENTERPRISE_ID_PATTERN
public static final java.util.regex.Pattern ENTERPRISE_ID_PATTERN
For now, avoid too restrictive OID checks to allow for easier transition
-
DEFAULT_MDCID
public static final java.lang.String DEFAULT_MDCID
Default MDC ID: "mdc" .- See Also:
- Constant Field Values
-
LF
private static final java.lang.String LF
- See Also:
- Constant Field Values
-
TWO_DIGITS
private static final int TWO_DIGITS
- See Also:
- Constant Field Values
-
THREE_DIGITS
private static final int THREE_DIGITS
- See Also:
- Constant Field Values
-
MILLIS_PER_MINUTE
private static final int MILLIS_PER_MINUTE
- See Also:
- Constant Field Values
-
MINUTES_PER_HOUR
private static final int MINUTES_PER_HOUR
- See Also:
- Constant Field Values
-
COMPONENT_KEY
private static final java.lang.String COMPONENT_KEY
- See Also:
- Constant Field Values
-
facility
private final Facility facility
-
defaultId
private final java.lang.String defaultId
-
enterpriseNumber
private final java.lang.String enterpriseNumber
-
includeMdc
private final boolean includeMdc
-
mdcId
private final java.lang.String mdcId
-
mdcSdId
private final StructuredDataId mdcSdId
-
localHostName
private final java.lang.String localHostName
-
appName
private final java.lang.String appName
-
messageId
private final java.lang.String messageId
-
configName
private final java.lang.String configName
-
mdcPrefix
private final java.lang.String mdcPrefix
-
eventPrefix
private final java.lang.String eventPrefix
-
mdcExcludes
private final java.util.List<java.lang.String> mdcExcludes
-
mdcIncludes
private final java.util.List<java.lang.String> mdcIncludes
-
mdcRequired
private final java.util.List<java.lang.String> mdcRequired
-
listChecker
private final ListChecker listChecker
-
includeNewLine
private final boolean includeNewLine
-
escapeNewLine
private final java.lang.String escapeNewLine
-
useTlsMessageFormat
private final boolean useTlsMessageFormat
-
lastTimestamp
private long lastTimestamp
-
timestamppStr
private java.lang.String timestamppStr
-
exceptionFormatters
private final java.util.List<PatternFormatter> exceptionFormatters
-
fieldFormatters
private final java.util.Map<java.lang.String,Rfc5424Layout.FieldFormatter> fieldFormatters
-
procId
private final java.lang.String procId
-
-
Constructor Detail
-
Rfc5424Layout
private Rfc5424Layout(Configuration config, Facility facility, java.lang.String id, java.lang.String ein, boolean includeMDC, boolean includeNL, java.lang.String escapeNL, java.lang.String mdcId, java.lang.String mdcPrefix, java.lang.String eventPrefix, java.lang.String appName, java.lang.String messageId, java.lang.String excludes, java.lang.String includes, java.lang.String required, java.nio.charset.Charset charset, java.lang.String exceptionPattern, boolean useTLSMessageFormat, LoggerFields[] loggerFields)
-
-
Method Detail
-
createFieldFormatters
private java.util.Map<java.lang.String,Rfc5424Layout.FieldFormatter> createFieldFormatters(LoggerFields[] loggerFields, Configuration config)
-
createPatternParser
private static PatternParser createPatternParser(Configuration config, java.lang.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
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
Gets this Rfc5424Layout's content format. Specified by:- Key: "structured" Value: "true"
- Key: "format" Value: "RFC5424"
- Specified by:
getContentFormatin interfaceLayout<java.lang.String>- Overrides:
getContentFormatin classAbstractLayout<java.lang.String>- Returns:
- Map of content format keys supporting Rfc5424Layout
-
toSerializable
public java.lang.String toSerializable(LogEvent event)
Formats aLogEventin conformance with the RFC 5424 Syslog specification.- Parameters:
event- The LogEvent.- Returns:
- The RFC 5424 String representation of the LogEvent.
-
appendPriority
private void appendPriority(java.lang.StringBuilder buffer, Level logLevel)
-
appendTimestamp
private void appendTimestamp(java.lang.StringBuilder buffer, long milliseconds)
-
appendSpace
private void appendSpace(java.lang.StringBuilder buffer)
-
appendHostName
private void appendHostName(java.lang.StringBuilder buffer)
-
appendAppName
private void appendAppName(java.lang.StringBuilder buffer)
-
appendProcessId
private void appendProcessId(java.lang.StringBuilder buffer)
-
appendMessageId
private void appendMessageId(java.lang.StringBuilder buffer, Message message)
-
appendMessage
private void appendMessage(java.lang.StringBuilder buffer, LogEvent event)
-
appendStructuredElements
private void appendStructuredElements(java.lang.StringBuilder buffer, LogEvent event)
-
addStructuredData
private void addStructuredData(java.util.Map<java.lang.String,Rfc5424Layout.StructuredDataElement> sdElements, StructuredDataMessage data)
-
escapeNewlines
private java.lang.String escapeNewlines(java.lang.String text, java.lang.String replacement)
-
getProcId
protected java.lang.String getProcId()
-
getMdcExcludes
protected java.util.List<java.lang.String> getMdcExcludes()
-
getMdcIncludes
protected java.util.List<java.lang.String> getMdcIncludes()
-
computeTimeStampString
private java.lang.String computeTimeStampString(long now)
-
pad
private void pad(int val, int max, java.lang.StringBuilder buf)
-
formatStructuredElement
private void formatStructuredElement(java.lang.String id, Rfc5424Layout.StructuredDataElement data, java.lang.StringBuilder sb, ListChecker checker)
-
getId
private java.lang.String getId(StructuredDataId id)
-
checkRequired
private void checkRequired(java.util.Map<java.lang.String,java.lang.String> map)
-
appendMap
private void appendMap(java.lang.String prefix, java.util.Map<java.lang.String,java.lang.String> map, java.lang.StringBuilder sb, ListChecker checker)
-
escapeSDParams
private java.lang.String escapeSDParams(java.lang.String value)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
createLayout
@PluginFactory public static Rfc5424Layout createLayout(@PluginAttribute(value="facility",defaultString="LOCAL0") Facility facility, @PluginAttribute("id") java.lang.String id, @PluginAttribute(value="enterpriseNumber",defaultInt=32473) int enterpriseNumber, @PluginAttribute(value="includeMDC",defaultBoolean=true) boolean includeMDC, @PluginAttribute(value="mdcId",defaultString="mdc") java.lang.String mdcId, @PluginAttribute("mdcPrefix") java.lang.String mdcPrefix, @PluginAttribute("eventPrefix") java.lang.String eventPrefix, @PluginAttribute("newLine") boolean newLine, @PluginAttribute("newLineEscape") java.lang.String escapeNL, @PluginAttribute("appName") java.lang.String appName, @PluginAttribute("messageId") java.lang.String msgId, @PluginAttribute("mdcExcludes") java.lang.String excludes, @PluginAttribute("mdcIncludes") java.lang.String includes, @PluginAttribute("mdcRequired") java.lang.String required, @PluginAttribute("exceptionPattern") java.lang.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
public Facility getFacility()
-
getDefaultId
public java.lang.String getDefaultId()
-
getEnterpriseNumber
public java.lang.String getEnterpriseNumber()
-
isIncludeMdc
public boolean isIncludeMdc()
-
getMdcId
public java.lang.String getMdcId()
-
-