The pattern provider allows you to define a JSON template using Logback's PatternLayout conversion specifiers. The encoder will populate the values within the template.
Type Conversion Operations
Because patterns are processed as strings, you can use special operations to ensure correct JSON types:
#asLong{...}: Converts resulting string to a Long (or null).#asDouble{...}: Converts resulting string to a Double (or null).#asBoolean{...}: Converts resulting string to a Boolean. Supports true, yes, y, 1 as true.asNullIfEmpty{...}: Converts empty string to null.#asJson{...}: Converts resulting string to a JSON object (or null).#tryJson{...}: Converts to JSON, or keeps as string if conversion fails.#nullNA{...}: (AccessEvents only) Replaces a dash (-) with null.
Omitting Empty Fields
Set <omitEmptyFields>true</omitEmptyFields> to remove fields from the output if they are null, empty strings, empty arrays, or empty objects.
<pattern>
<pattern>
{
"line_str": "%line",
"line_long": "#asLong{%line}",
"has_message": "#asBoolean{%mdc{hasMessage}}",
"json_message": "#asJson{%message}"
}
</pattern>
</pattern>