Package org.logevents.formatters
Class PatternLogEventFormatter
- java.lang.Object
-
- org.logevents.formatters.PatternLogEventFormatter
-
- All Implemented Interfaces:
Function<LogEvent,String>,LogEventFormatter
public class PatternLogEventFormatter extends Object implements LogEventFormatter
This class represents aLogEventFormatterwhich outputs theLogEventbased 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 withPatternConverterSpecWithSubpattern. A conversion is specified with a conversion word, and you can extendPatternLogEventFormatterwith 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 fromDateTimeFormatter.ofPattern(java.lang.String)e.g. %date{DD-MMM HH:mm:ss}. Default format isyyyy-MM-dd HH:mm:ss.SSS. %time: As %date, but with default formatHH: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 allMDCvariables. Use %mdc{key:-default} to display a single mdc variable, or withConfiguration.getMdcFilter(). If MDC values are printed, the MDC string is prefixed with a space -
%kvp: The values ofLogEvent.getKeyValuePairs()}. The value part is surrounded by double quotes and each pair is separated by space, for examplek1="v1" k2="v2" k3="v3" %application: The value ofConfiguration.getApplicationName()%node: The value ofConfiguration.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
-
-
Constructor Summary
Constructors Constructor Description PatternLogEventFormatter(String pattern)PatternLogEventFormatter(String pattern, Configuration configuration)PatternLogEventFormatter(Map<String,String> properties, String prefix)PatternLogEventFormatter(Configuration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringapply(LogEvent event)Collection<String>getConversionWords()Optional<ExceptionFormatter>getExceptionFormatter()voidsetPattern(String pattern)StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.logevents.LogEventFormatter
configure
-
-
-
-
Constructor Detail
-
PatternLogEventFormatter
public PatternLogEventFormatter(String pattern)
-
PatternLogEventFormatter
public PatternLogEventFormatter(Map<String,String> properties, String prefix)
-
PatternLogEventFormatter
public PatternLogEventFormatter(Configuration configuration)
-
PatternLogEventFormatter
public PatternLogEventFormatter(String pattern, Configuration configuration)
-
-
Method Detail
-
getConversionWords
public Collection<String> getConversionWords()
-
getExceptionFormatter
public Optional<ExceptionFormatter> getExceptionFormatter()
- Specified by:
getExceptionFormatterin interfaceLogEventFormatter
-
setPattern
public void setPattern(String pattern)
-
-