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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<PatternFormatter> Deprecated.Kept for binary backward compatibility.protected final ThrowableFormatOptionsprivate final ThrowableRendererFields inherited from class org.apache.logging.log4j.core.pattern.AbstractPatternConverter
LOGGERFields inherited from interface org.apache.logging.log4j.core.pattern.PatternConverter
CATEGORY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedThrowablePatternConverter(String name, String style, @Nullable String[] options) protectedThrowablePatternConverter(String name, String style, @Nullable String[] options, @Nullable Configuration config) (package private)ThrowablePatternConverter(String name, String style, @Nullable String[] options, @Nullable Configuration config, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory) The canonical constructor. -
Method Summary
Modifier and TypeMethodDescriptioncreateEffectiveLineSeparator(String separator, @Nullable String suffix, @Nullable Configuration config, List<PatternFormatter> suffixFormatters) Creates a lambda that returns the effective line separator by concatenating the formattedsuffixwith theseparator.private static ThrowableRenderercreateEffectiveRenderer(String[] rawOptions, ThrowableFormatOptions options, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory) voidformat(LogEvent event, StringBuilder buffer) Formats an event into a string buffer.protected StringDeprecated.Planned to be removed without a replacementbooleanIndicates this converter handlesThrowables.static ThrowablePatternConverternewInstance(@Nullable Configuration config, @Nullable String[] options) Creates an instance of the class.Methods inherited from class org.apache.logging.log4j.core.pattern.LogEventPatternConverter
emptyVariableOutput, format, isVariableMethods inherited from class org.apache.logging.log4j.core.pattern.AbstractPatternConverter
getName, getStyleClass
-
Field Details
-
formatters
Deprecated.Kept for binary backward compatibility.Returns the list of formatters used to render the suffix. -
effectiveLineSeparatorProvider
-
options
-
renderer
-
-
Constructor Details
-
ThrowablePatternConverter
@Deprecated protected ThrowablePatternConverter(String name, String style, @Nullable String[] options) -
ThrowablePatternConverter
@Deprecated protected ThrowablePatternConverter(String name, String style, @Nullable String[] options, @Nullable Configuration config) -
ThrowablePatternConverter
ThrowablePatternConverter(String name, String style, @Nullable 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 Details
-
newInstance
public static ThrowablePatternConverter newInstance(@Nullable Configuration config, @Nullable String[] options) Creates an instance of the class.- Parameters:
config- a configurationoptions- the pattern options- Returns:
- a new instance
-
format
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
-
createEffectiveLineSeparator
private static Function<LogEvent,String> createEffectiveLineSeparator(String separator, @Nullable String suffix, @Nullable Configuration config, 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(String[] rawOptions, ThrowableFormatOptions options, @Nullable ThrowablePropertyRendererFactory propertyRendererFactory, @Nullable ThrowableStackTraceRendererFactory stackTraceRendererFactory) -
getSuffix
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
-