Package net.logstash.logback.stacktrace
Class ShortenedThrowableConverter
java.lang.Object
ch.qos.logback.core.pattern.Converter<E>
ch.qos.logback.core.pattern.FormattingConverter<E>
ch.qos.logback.core.pattern.DynamicConverter<ILoggingEvent>
ch.qos.logback.classic.pattern.ClassicConverter
ch.qos.logback.classic.pattern.ThrowableHandlingConverter
net.logstash.logback.stacktrace.ShortenedThrowableConverter
- All Implemented Interfaces:
ContextAware
,LifeCycle
A
ThrowableHandlingConverter
(similar to logback's ThrowableProxyConverter
)
that formats stacktraces by doing the following:
- Limits the number of stackTraceElements per throwable
(applies to each individual throwable. e.g. caused-bys and suppressed).
See
maxDepthPerThrowable
. - Limits the total length in characters of the trace.
See
maxLength
. - Abbreviates class names based.
See
setShortenedClassNameLength(int)
. - Filters out consecutive unwanted stackTraceElements based on regular expressions.
See
excludes
. - Truncate individual stacktraces after any element matching one the configured
regular expression.
See
truncateAfterPatterns
. - Uses evaluators to determine if the stacktrace should be logged.
See
evaluators
. - Outputs in either 'normal' order (root-cause-last), or root-cause-first.
See
rootCauseFirst
.
PatternLayout
, you must configure conversionRule
as described here.
Options can be specified in the pattern in the following order:
- maxDepthPerThrowable = "full" or "short" or an integer value
- shortenedClassNameLength = "full" or "short" or an integer value
- maxLength = "full" or "short" or an integer value
- "rootFirst" - indicating that stacks should be printed root-cause first
- "inlineHash" - indicating that hexadecimal error hashes should be computed and inlined
- "inline" - indicating that the whole stack trace should be inlined, using "\\n" as separator
- "omitCommonFrames" - omit common frames
- "keepCommonFrames" - keep common frames
- evaluator name - name of evaluators that will determine if the stacktrace is ignored
- exclusion pattern - pattern for stack trace elements to exclude
For example,
<conversionRule conversionWord="stack"
converterClass="net.logstash.logback.stacktrace.ShortenedThrowableConverter" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%thread] - %msg%n%stack{5,1024,10,rootFirst,omitCommonFrames,regex1,regex2,evaluatorName}</pattern>
</encoder>
</appender>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final String
String sequence to use to delimit lines instead ofCoreConstants.LINE_SEPARATOR
when inline is activestatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class ch.qos.logback.core.pattern.DynamicConverter
started
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEvaluator
(EventEvaluator<ILoggingEvent> evaluator) void
addExclude
(String exclusionPattern) void
addExclusions
(String commaSeparatedPatterns) Add multiple exclusion patterns as a list of comma separated patternsvoid
addTruncateAfter
(String regex) void
addTruncateAfters
(String commaSeparatedPatterns) Add multiple truncate after patterns as a list of comma separated patterns.convert
(ILoggingEvent event) int
int
int
Get the class name abbreviation target length.boolean
boolean
boolean
void
setClassNameAbbreviator
(Abbreviator abbreviator) Set a customAbbreviator
used to shorten class names.void
setEvaluators
(List<EventEvaluator<ILoggingEvent>> evaluators) void
setExcludes
(List<String> patterns) void
setInlineHash
(boolean inlineHash) void
setLineSeparator
(String lineSeparator) Sets which lineSeparator to use between events.void
setMaxDepthPerThrowable
(int maxDepthPerThrowable) Set a limit on the number of stackTraceElements per throwable.void
setMaxLength
(int maxLength) Set a hard limit on the size of the rendered stacktrace, all throwables included.void
setOmitCommonFrames
(boolean omitCommonFrames) Control whether common frames should be omitted for nested throwables or not.void
setRootCauseFirst
(boolean rootCauseFirst) void
setShortenedClassNameLength
(int length) Set the length to which class names should be abbreviated.void
setTruncateAfters
(List<String> patterns) void
start()
void
stop()
Methods inherited from class ch.qos.logback.core.pattern.DynamicConverter
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getFirstOption, getOptionList, isStarted, setContext, setOptionList
Methods inherited from class ch.qos.logback.core.pattern.FormattingConverter
getFormattingInfo, setFormattingInfo, write
-
Field Details
-
FULL_MAX_DEPTH_PER_THROWABLE
public static final int FULL_MAX_DEPTH_PER_THROWABLE- See Also:
-
SHORT_MAX_DEPTH_PER_THROWABLE
public static final int SHORT_MAX_DEPTH_PER_THROWABLE- See Also:
-
DEFAULT_MAX_DEPTH_PER_THROWABLE
public static final int DEFAULT_MAX_DEPTH_PER_THROWABLE- See Also:
-
FULL_MAX_LENGTH
public static final int FULL_MAX_LENGTH- See Also:
-
SHORT_MAX_LENGTH
public static final int SHORT_MAX_LENGTH- See Also:
-
DEFAULT_MAX_LENGTH
public static final int DEFAULT_MAX_LENGTH- See Also:
-
FULL_CLASS_NAME_LENGTH
public static final int FULL_CLASS_NAME_LENGTH- See Also:
-
SHORT_CLASS_NAME_LENGTH
public static final int SHORT_CLASS_NAME_LENGTH- See Also:
-
DEFAULT_CLASS_NAME_LENGTH
public static final int DEFAULT_CLASS_NAME_LENGTH- See Also:
-
DEFAULT_INLINE_SEPARATOR
String sequence to use to delimit lines instead ofCoreConstants.LINE_SEPARATOR
when inline is active- See Also:
-
-
Constructor Details
-
ShortenedThrowableConverter
public ShortenedThrowableConverter()
-
-
Method Details
-
start
public void start()- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classDynamicConverter<ILoggingEvent>
-
stop
public void stop()- Specified by:
stop
in interfaceLifeCycle
- Overrides:
stop
in classDynamicConverter<ILoggingEvent>
-
convert
- Specified by:
convert
in classConverter<ILoggingEvent>
-
setLineSeparator
Sets which lineSeparator to use between events.The following values have special meaning:
null
or empty string = no new line.- "
SYSTEM
" = operating system new line (default). - "
UNIX
" = unix line ending (\n
). - "
WINDOWS
" = windows line ending\r\n
).
Any other value will be used as given as the lineSeparator.
- Parameters:
lineSeparator
- the line separator
-
getLineSeparator
-
setShortenedClassNameLength
public void setShortenedClassNameLength(int length) Set the length to which class names should be abbreviated. Cannot be used if a customAbbreviator
has been set throughsetClassNameAbbreviator(Abbreviator)
.- Parameters:
length
- the desired maximum length or-1
to disable the feature and allow for any arbitrary length.
-
getShortenedClassNameLength
public int getShortenedClassNameLength()Get the class name abbreviation target length. Cannot be used if a customAbbreviator
has been set throughsetClassNameAbbreviator(Abbreviator)
.- Returns:
- the abbreviation target length
-
setClassNameAbbreviator
Set a customAbbreviator
used to shorten class names.- Parameters:
abbreviator
- theAbbreviator
to use.
-
getClassNameAbbreviator
-
setMaxDepthPerThrowable
public void setMaxDepthPerThrowable(int maxDepthPerThrowable) Set a limit on the number of stackTraceElements per throwable. Use-1
to disable the feature and allow for an unlimited depth.- Parameters:
maxDepthPerThrowable
- the maximum number of stacktrace elements per throwable or-1
to disable the feature and allows for an unlimited amount.
-
getMaxDepthPerThrowable
public int getMaxDepthPerThrowable() -
setMaxLength
public void setMaxLength(int maxLength) Set a hard limit on the size of the rendered stacktrace, all throwables included. Use-1
to disable the feature and allows for any size.- Parameters:
maxLength
- the maximum size of the rendered stacktrace or-1
for no limit.
-
getMaxLength
public int getMaxLength() -
setOmitCommonFrames
public void setOmitCommonFrames(boolean omitCommonFrames) Control whether common frames should be omitted for nested throwables or not.- Parameters:
omitCommonFrames
-true
to omit common frames
-
isOmitCommonFrames
public boolean isOmitCommonFrames() -
isRootCauseFirst
public boolean isRootCauseFirst() -
setRootCauseFirst
public void setRootCauseFirst(boolean rootCauseFirst) -
isInlineHash
public boolean isInlineHash() -
setInlineHash
public void setInlineHash(boolean inlineHash) -
addExclude
-
addExclusions
Add multiple exclusion patterns as a list of comma separated patterns- Parameters:
commaSeparatedPatterns
- list of comma separated patterns
-
setExcludes
-
getExcludes
-
addTruncateAfter
-
getTruncateAfters
-
addTruncateAfters
Add multiple truncate after patterns as a list of comma separated patterns.- Parameters:
commaSeparatedPatterns
- list of comma separated patterns
-
setTruncateAfters
-
addEvaluator
-
setEvaluators
-
getEvaluators
-