Class PatternLogEventFormatter

  • All Implemented Interfaces:
    Function<LogEvent,​String>, LogEventFormatter

    public class PatternLogEventFormatter
    extends Object
    implements LogEventFormatter
    This class represents a LogEventFormatter which outputs the LogEvent based on a configured pattern. The pattern consists of constant parts and conversion parts, which starts with %-signs. The general format for conversion parts is %[<minlength>][.<maxlength>]<conversion word>[(<conversion subpattern>)][{<parameter>,<parameter>}]. Conversion parts are handled with PatternConverterSpecWithSubpattern. A conversion is specified with a conversion word, and you can extend PatternLogEventFormatter with your own conversion words by adding them to the ConverterBuilderFactory.

    The following conversion words are supported:

    • %logger: The logger (category)
    • %class: The logging class (you should prefer %logger as it's more performant)
    • %location: The filename and line number in a format that's usually clickable, e.g. LogEvent.getSimpleCallerLocation(LogEvent.java:259)
    • %file: The logging class filename
    • %line: The line number of the logging call
    • %date: The date and time of the log event. Optionally supports a date formatting pattern from DateTimeFormatter.ofPattern(java.lang.String) e.g. %date{DD-MMM HH:mm:ss}. Default format is yyyy-MM-dd HH:mm:ss.SSS.
    • %time: As %date, but with default format HH:mm:ss.SSS
    • %level
    • %coloredLevel: As level, but ERROR is bold red, WARN is red, and INFO is blue
    • %message: Message with arguments merged in
    • %thread
    • %marker: Marker (if any)
    • %mdc: will print all MDC variables. Use %mdc{key:-default} to display a single mdc variable, or with Configuration.getMdcFilter(). If MDC values are printed, the MDC string is prefixed with a space
    • %kvp: The values of LogEvent.getKeyValuePairs()}. The value part is surrounded by double quotes and each pair is separated by space, for example k1="v1" k2="v2" k3="v3"
    • %application: The value of Configuration.getApplicationName()
    • %node: The value of Configuration.getNodeName() ()}
    • %highlight(<subpattern<): Highlights the subpattern based on the log level of the message: ERROR is bold red, WARN is red, and INFO is blue
    • Colors: E.g. %boldGreen(%thread). The following are supported: %black(...), %red(...), %green(...) %yellow(...), %blue(...), %magenta(...), %cyan(...), %white(...), as well as %bold(...), %italic(...), %underline(...) and %boldcolor(...) for all colors

    Ansi colors will be used if running on a non-Windows shell or if JANSI is in class path. (Color on Windows is supported in IntelliJ, Cygwin and Ubuntu for Windows)

    Author:
    Johannes Brodwall