Class YamlLayout

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

    @Plugin(name="YamlLayout",
            category="Core",
            elementType="layout",
            printObject=true)
    public final class YamlLayout
    extends AbstractStringLayout
    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 Detail

      • eol

        protected final String eol
      • objectWriter

        protected final com.fasterxml.jackson.databind.ObjectWriter objectWriter
      • compact

        protected final boolean compact
      • complete

        protected final boolean complete
      • includeNullDelimiter

        protected final boolean includeNullDelimiter
      • additionalFields

        protected final org.apache.logging.log4j.core.layout.AbstractJacksonLayout.ResolvableKeyValuePair[] additionalFields
    • Constructor Detail

      • 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
    • Method Detail

      • createLayout

        @Deprecated
        public static org.apache.logging.log4j.core.layout.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.
      • createDefaultLayout

        public static org.apache.logging.log4j.core.layout.AbstractJacksonLayout createDefaultLayout()
        Creates a YAML Layout using the default settings. Useful for testing.
        Returns:
        A YAML Layout.
      • valueNeedsLookup

        protected static boolean valueNeedsLookup​(String value)
      • toSerializable

        public String toSerializable​(LogEvent event)
        Formats a LogEvent.
        Parameters:
        event - The LogEvent.
        Returns:
        The XML representation of the LogEvent.
      • toSerializable

        public void toSerializable​(LogEvent event,
                                   Writer writer)
                            throws com.fasterxml.jackson.core.JsonGenerationException,
                                   com.fasterxml.jackson.databind.JsonMappingException,
                                   IOException
        Throws:
        com.fasterxml.jackson.core.JsonGenerationException
        com.fasterxml.jackson.databind.JsonMappingException
        IOException