Class YamlLayout

  • All Implemented Interfaces:
    LocationAware, Layout<java.lang.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.

    • Constructor Detail

      • YamlLayout

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

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

      • getHeader

        public byte[] getHeader()
        Returns appropriate YAML header.
        Specified by:
        getHeader in interface Layout<java.lang.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<java.lang.String>
        Overrides:
        getFooter in class AbstractStringLayout
        Returns:
        a byte array containing the footer, closing the YAML array.
      • getContentFormat

        public java.util.Map<java.lang.String,​java.lang.String> getContentFormat()
        Description copied from interface: Layout
        Returns a description of the content format.
        Specified by:
        getContentFormat in interface Layout<java.lang.String>
        Overrides:
        getContentFormat in class AbstractLayout<java.lang.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 java.lang.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<java.lang.String>
        Overrides:
        getContentType in class AbstractStringLayout
        Returns:
        The content type.
      • createLayout

        @Deprecated
        public static AbstractJacksonLayout createLayout​(Configuration config,
                                                         boolean locationInfo,
                                                         boolean properties,
                                                         java.lang.String headerPattern,
                                                         java.lang.String footerPattern,
                                                         java.nio.charset.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.
      • createDefaultLayout

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