Class YamlLayout

All Implemented Interfaces:
LocationAware, Layout<String>, Encoder<LogEvent>, StringLayout

@Plugin(name="YamlLayout", category="Core", elementType="layout", printObject=true) public final class YamlLayout extends AbstractJacksonLayout
Appends a series of YAML events as strings serialized as bytes.

Encoding

Appenders using this layout should have their charset set to UTF-8 or UTF-16, otherwise events containing non ASCII characters could result in corrupted log files.

Additional Fields

This property allows addition of custom fields into generated JSON. <YamlLayout><KeyValuePair key="foo" value="bar"/></YamlLayout> inserts foo: "bar" directly into YAML output. Supports Lookup expressions.

  • Field Details

  • Constructor Details

    • YamlLayout

      @Deprecated protected YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace)
      Deprecated.
      Use newBuilder() instead
    • YamlLayout

      private YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String endOfLine, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace, boolean stacktraceAsString, boolean includeNullDelimiter, boolean includeTimeMillis, KeyValuePair[] additionalFields)
  • Method Details

    • getHeader

      public byte[] getHeader()
      Returns appropriate YAML header.
      Specified by:
      getHeader in interface Layout<String>
      Overrides:
      getHeader in class AbstractStringLayout
      Returns:
      a byte array containing the header, opening the YAML array.
    • getFooter

      public byte[] getFooter()
      Returns appropriate YAML footer.
      Specified by:
      getFooter in interface Layout<String>
      Overrides:
      getFooter in class AbstractStringLayout
      Returns:
      a byte array containing the footer, closing the YAML array.
    • getContentFormat

      public Map<String,String> getContentFormat()
      Description copied from interface: Layout
      Returns a description of the content format.
      Specified by:
      getContentFormat in interface Layout<String>
      Overrides:
      getContentFormat in class AbstractLayout<String>
      Returns:
      a Map of key/value pairs describing the Layout-specific content format, or an empty Map if no content format descriptors are specified.
    • getContentType

      public String getContentType()
      Description copied from interface: Layout
      Returns the content type output by this layout. The base class returns "text/plain".
      Specified by:
      getContentType in interface Layout<String>
      Overrides:
      getContentType in class AbstractStringLayout
      Returns:
      The content type.
    • createLayout

      @Deprecated public static AbstractJacksonLayout createLayout(Configuration config, boolean locationInfo, boolean properties, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace)
      Deprecated.
      Use newBuilder() instead
      Creates a YAML Layout.
      Parameters:
      config - The plugin configuration.
      locationInfo - If "true", includes the location information in the generated YAML.
      properties - If "true", includes the thread context map in the generated YAML.
      headerPattern - The header pattern, defaults to "" if null.
      footerPattern - The header pattern, defaults to "" if null.
      charset - The character set to use, if null, uses "UTF-8".
      includeStacktrace - If "true", includes the stacktrace of any Throwable in the generated YAML, defaults to "true".
      Returns:
      A YAML Layout.
    • newBuilder

      @PluginBuilderFactory public static <B extends YamlLayout.Builder<B>> B newBuilder()
    • createDefaultLayout

      public static AbstractJacksonLayout createDefaultLayout()
      Creates a YAML Layout using the default settings. Useful for testing.
      Returns:
      A YAML Layout.