Class 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:
  • Field Details

    • DEFAULT_ENTERPRISE_NUMBER

      public static final int DEFAULT_ENTERPRISE_NUMBER
      The default example enterprise number from RFC5424.
      See Also:
    • DEFAULT_ID

      public static final String DEFAULT_ID
      The default event id.
      See Also:
    • NEWLINE_PATTERN

      public static final Pattern NEWLINE_PATTERN
      Match newlines in a platform-independent manner.
    • PARAM_VALUE_ESCAPE_PATTERN

      @Deprecated public static final Pattern PARAM_VALUE_ESCAPE_PATTERN
      Deprecated.
      Match characters which require escaping.
    • ENTERPRISE_ID_PATTERN

      public static final Pattern ENTERPRISE_ID_PATTERN
      For now, avoid too restrictive OID checks to allow for easier transition
    • DEFAULT_MDCID

      public static final String DEFAULT_MDCID
      Default MDC ID: "mdc" .
      See Also:
    • SD_PARAM_NAME_MAX_LENGTH

      private static final int SD_PARAM_NAME_MAX_LENGTH
      See Also:
    • LF

      private static final String 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

      private static final String COMPONENT_KEY
      See Also:
    • facility

      private final Facility facility
    • defaultId

      private final String defaultId
    • enterpriseNumber

      private final String enterpriseNumber
    • includeMdc

      private final boolean includeMdc
    • mdcId

      private final String mdcId
    • mdcSdId

      private final StructuredDataId mdcSdId
    • localHostName

      private final String localHostName
    • appName

      private final String appName
    • messageId

      private final String messageId
    • configName

      private final String configName
    • mdcPrefix

      private final String mdcPrefix
    • eventPrefix

      private final String eventPrefix
    • mdcExcludes

      private final List<String> mdcExcludes
    • mdcIncludes

      private final List<String> mdcIncludes
    • mdcRequired

      private final List<String> mdcRequired
    • listChecker

      private final ListChecker listChecker
    • includeNewLine

      private final boolean includeNewLine
    • escapeNewLine

      private final String escapeNewLine
    • useTlsMessageFormat

      private final boolean useTlsMessageFormat
    • lastTimestamp

      private long lastTimestamp
    • timestamppStr

      private String timestamppStr
    • exceptionFormatters

      private final List<PatternFormatter> exceptionFormatters
    • fieldFormatters

      private final Map<String, Rfc5424Layout.FieldFormatter> fieldFormatters
    • procId

      private final String procId
  • Constructor Details

  • 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

      public Map<String,String> getContentFormat()
      Gets this Rfc5424Layout's content format. Specified by:
      • Key: "structured" Value: "true"
      • Key: "format" Value: "RFC5424"
      Specified by:
      getContentFormat in interface Layout<String>
      Overrides:
      getContentFormat in class AbstractLayout<String>
      Returns:
      Map of content format keys supporting Rfc5424Layout
    • toSerializable

      public String toSerializable(LogEvent event)
      Formats a LogEvent in conformance with the RFC 5424 Syslog specification.
      Parameters:
      event - The LogEvent.
      Returns:
      The RFC 5424 String representation of the LogEvent.
    • appendPriority

      private void appendPriority(StringBuilder buffer, Level logLevel)
    • appendTimestamp

      private void appendTimestamp(StringBuilder buffer, long milliseconds)
    • appendSpace

      private void appendSpace(StringBuilder buffer)
    • appendHostName

      private void appendHostName(StringBuilder buffer)
    • appendAppName

      private void appendAppName(StringBuilder buffer)
    • appendProcessId

      private void appendProcessId(StringBuilder buffer)
    • appendMessageId

      private void appendMessageId(StringBuilder buffer, Message message)
    • appendMessage

      private void appendMessage(StringBuilder buffer, LogEvent event)
    • appendStructuredElements

      private void appendStructuredElements(StringBuilder buffer, LogEvent event)
    • addStructuredData

      private void addStructuredData(Map<String, Rfc5424Layout.StructuredDataElement> sdElements, StructuredDataMessage data)
    • escapeNewlines

      private String escapeNewlines(String text, String replacement)
    • getProcId

      protected String getProcId()
    • getMdcExcludes

      protected List<String> getMdcExcludes()
    • getMdcIncludes

      protected List<String> getMdcIncludes()
    • getMdcRequired

      List<String> getMdcRequired()
    • isIncludeNewLine

      boolean isIncludeNewLine()
    • getEscapeNewLine

      String getEscapeNewLine()
    • isUseTlsMessageFormat

      boolean isUseTlsMessageFormat()
    • computeTimeStampString

      private String computeTimeStampString(long now)
    • pad

      private void pad(int val, int max, StringBuilder buf)
    • formatStructuredElement

      private void formatStructuredElement(String id, Rfc5424Layout.StructuredDataElement data, StringBuilder sb, ListChecker checker)
    • getId

      private String getId(StructuredDataId id)
    • checkRequired

      private void checkRequired(Map<String,String> map)
    • appendMap

      private void appendMap(String prefix, Map<String,String> map, StringBuilder sb, ListChecker checker)
    • sanitizeParamName

      private String sanitizeParamName(String key)
      Sanitizes an RFC 5424 PARAM-NAME

      Invalid characters are replaced with '?' and the result is truncated to 32.

      Parameters:
      key - the original parameter name
      Returns:
      a sanitized parameter name compliant with RFC 5424
    • sanitizeParamNameSlowPath

      private String sanitizeParamNameSlowPath(String key)
    • isParamNameCharacterValid

      private static boolean isParamNameCharacterValid(char c)
      Checks whether a character is allowed in an RFC 5424 PARAM-NAME.

      Valid characters are printable US-ASCII characters (0x20-0x7E) excluding:

      • '=' – parameter delimiter
      • ' ' – not permitted in SD-NAME
      • ']' – structured data terminator
      • '"' – quoting delimiter
      Parameters:
      c - the character to test
      Returns:
      true if the character is allowed in an SD-NAME
    • escapeParamValue

      private String escapeParamValue(String value)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createLayout

      @Deprecated public 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.
      Since 2.21.0 use instead
      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 patterns
      config - The Configuration. Some Converters require access to the Interpolator.
      Returns:
      An Rfc5424Layout.
    • newBuilder

      Since:
      2.21.0
    • getFacility

      public Facility getFacility()
    • getDefaultId

      public String getDefaultId()
    • getEnterpriseNumber

      public String getEnterpriseNumber()
    • isIncludeMdc

      public boolean isIncludeMdc()
    • getMdcId

      public String getMdcId()
    • getLocalHostName

      String getLocalHostName()