Class ThrowablePatternConverter
- java.lang.Object
-
- org.apache.logging.log4j.core.pattern.AbstractPatternConverter
-
- org.apache.logging.log4j.core.pattern.LogEventPatternConverter
-
- org.apache.logging.log4j.core.pattern.ThrowablePatternConverter
-
- All Implemented Interfaces:
PatternConverter
- Direct Known Subclasses:
ExtendedThrowablePatternConverter,RootThrowablePatternConverter
@NullMarked @Plugin(name="ThrowablePatternConverter", category="Converter") public class ThrowablePatternConverter extends LogEventPatternConverter
Outputs certain information extracted from theThrowableassociated with aLogEvent.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Function<LogEvent,java.lang.String>effectiveLineSeparatorProviderprotected java.util.List<PatternFormatter>formattersDeprecated.Kept for binary backward compatibility.protected ThrowableFormatOptionsoptionsprivate ThrowableRendererrenderer-
Fields inherited from class org.apache.logging.log4j.core.pattern.AbstractPatternConverter
LOGGER
-
Fields inherited from interface org.apache.logging.log4j.core.pattern.PatternConverter
CATEGORY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedThrowablePatternConverter(java.lang.String name, java.lang.String style, @Nullable java.lang.String[] options)protectedThrowablePatternConverter(java.lang.String name, java.lang.String style, @Nullable java.lang.String[] options, @Nullable Configuration config)(package private)ThrowablePatternConverter(java.lang.String name, java.lang.String style, @Nullable java.lang.String[] options, @Nullable Configuration config, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory)The canonical constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static java.util.function.Function<LogEvent,java.lang.String>createEffectiveLineSeparator(java.lang.String separator, @Nullable java.lang.String suffix, @Nullable Configuration config, java.util.List<PatternFormatter> suffixFormatters)Creates a lambda that returns the effective line separator by concatenating the formattedsuffixwith theseparator.private static ThrowableRenderercreateEffectiveRenderer(java.lang.String[] rawOptions, ThrowableFormatOptions options, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory)voidformat(LogEvent event, java.lang.StringBuilder buffer)Formats an event into a string buffer.ThrowableFormatOptionsgetOptions()protected java.lang.StringgetSuffix(LogEvent logEvent)Deprecated.Planned to be removed without a replacementbooleanhandlesThrowable()Indicates this converter handlesThrowables.static ThrowablePatternConverternewInstance(@Nullable Configuration config, @Nullable java.lang.String[] options)Creates an instance of the class.-
Methods inherited from class org.apache.logging.log4j.core.pattern.LogEventPatternConverter
emptyVariableOutput, format, isVariable
-
Methods inherited from class org.apache.logging.log4j.core.pattern.AbstractPatternConverter
getName, getStyleClass
-
-
-
-
Field Detail
-
formatters
@Deprecated protected final java.util.List<PatternFormatter> formatters
Deprecated.Kept for binary backward compatibility.Returns the list of formatters used to render the suffix.
-
effectiveLineSeparatorProvider
private final java.util.function.Function<LogEvent,java.lang.String> effectiveLineSeparatorProvider
-
options
protected final ThrowableFormatOptions options
-
renderer
private final ThrowableRenderer renderer
-
-
Constructor Detail
-
ThrowablePatternConverter
@Deprecated protected ThrowablePatternConverter(java.lang.String name, java.lang.String style, @Nullable java.lang.String[] options)
-
ThrowablePatternConverter
@Deprecated protected ThrowablePatternConverter(java.lang.String name, java.lang.String style, @Nullable java.lang.String[] options, @Nullable Configuration config)
-
ThrowablePatternConverter
ThrowablePatternConverter(java.lang.String name, java.lang.String style, @Nullable java.lang.String[] options, @Nullable Configuration config, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory)The canonical constructor.- Parameters:
name- name of the converterstyle- CSS style for outputoptions- array of optionsconfig- a configurationstackTraceRendererFactory- a renderer factory- Since:
- 2.25.0
-
-
Method Detail
-
newInstance
public static ThrowablePatternConverter newInstance(@Nullable Configuration config, @Nullable java.lang.String[] options)
Creates an instance of the class.- Parameters:
config- a configurationoptions- the pattern options- Returns:
- a new instance
-
format
public void format(LogEvent event, java.lang.StringBuilder buffer)
Formats an event into a string buffer.- Specified by:
formatin classLogEventPatternConverter- Parameters:
event- event to format, may not be null.buffer- string buffer to which the formatted event will be appended. May not be null.
-
handlesThrowable
public boolean handlesThrowable()
Indicates this converter handlesThrowables.- Overrides:
handlesThrowablein classLogEventPatternConverter- Returns:
true
-
getOptions
public ThrowableFormatOptions getOptions()
-
createEffectiveLineSeparator
private static java.util.function.Function<LogEvent,java.lang.String> createEffectiveLineSeparator(java.lang.String separator, @Nullable java.lang.String suffix, @Nullable Configuration config, java.util.List<PatternFormatter> suffixFormatters)
Creates a lambda that returns the effective line separator by concatenating the formattedsuffixwith theseparator.At the beginning, there was only
separatorused as a terminator at the end of every rendered line. Its content was rendered literally without any processing.Later on,
suffixwas added in #61.suffixis functionally identical toseparatorwith the exception that it contains a Pattern Layout conversion pattern. In an ideal world,separatorshould have been extended to accept patterns. But without giving it a second of thought, just like almost any other Log4j feature, we cheerfully accepted the feature.Given two overlapping features, how do we determine the effective line separator?
String effectiveLineSeparator(String separator, String suffix, LogEvent event) { String formattedSuffix = format(suffix, event); return isNotBlank(formattedSuffix) ? (' ' + formattedSuffix + lineSeparator) : lineSeparator; }- Parameters:
separator- the user-providedseparatoroptionsuffix- the user-providedsuffixoption containing a Pattern Layout conversion patternconfig- the configuration to create the Pattern Layout conversion pattern parsersuffixFormatters- the list of pattern formatters employed to format the suffix- Returns:
- a lambda that returns the effective line separator by concatenating the formatted
suffixwith theseparator
-
createEffectiveRenderer
private static ThrowableRenderer createEffectiveRenderer(java.lang.String[] rawOptions, ThrowableFormatOptions options, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory)
-
getSuffix
@Deprecated protected java.lang.String getSuffix(LogEvent logEvent)
Deprecated.Planned to be removed without a replacementReturns the formatted suffix pattern.- Parameters:
logEvent- the log event to use while formatting the suffix pattern- Returns:
- the formatted suffix
-
-