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 intstatic final StringString sequence to use to delimit lines instead ofCoreConstants.LINE_SEPARATORwhen inline is activestatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class ch.qos.logback.core.pattern.DynamicConverter
started -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEvaluator(EventEvaluator<ILoggingEvent> evaluator) voidaddExclude(String exclusionPattern) voidaddExclusions(String commaSeparatedPatterns) Add multiple exclusion patterns as a list of comma separated patternsvoidaddTruncateAfter(String regex) voidaddTruncateAfters(String commaSeparatedPatterns) Add multiple truncate after patterns as a list of comma separated patterns.convert(ILoggingEvent event) intintintGet the class name abbreviation target length.booleanbooleanbooleanvoidsetClassNameAbbreviator(Abbreviator abbreviator) Set a customAbbreviatorused to shorten class names.voidsetEvaluators(List<EventEvaluator<ILoggingEvent>> evaluators) voidsetExcludes(List<String> patterns) voidsetInlineHash(boolean inlineHash) voidsetLineSeparator(String lineSeparator) Sets which lineSeparator to use between events.voidsetMaxDepthPerThrowable(int maxDepthPerThrowable) Set a limit on the number of stackTraceElements per throwable.voidsetMaxLength(int maxLength) Set a hard limit on the size of the rendered stacktrace, all throwables included.voidsetOmitCommonFrames(boolean omitCommonFrames) Control whether common frames should be omitted for nested throwables or not.voidsetRootCauseFirst(boolean rootCauseFirst) voidsetShortenedClassNameLength(int length) Set the length to which class names should be abbreviated.voidsetTruncateAfters(List<String> patterns) voidstart()voidstop()Methods inherited from class ch.qos.logback.core.pattern.DynamicConverter
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getFirstOption, getOptionList, isStarted, setContext, setOptionListMethods 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_SEPARATORwhen inline is active- See Also:
-
-
Constructor Details
-
ShortenedThrowableConverter
public ShortenedThrowableConverter()
-
-
Method Details
-
start
public void start()- Specified by:
startin interfaceLifeCycle- Overrides:
startin classDynamicConverter<ILoggingEvent>
-
stop
public void stop()- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classDynamicConverter<ILoggingEvent>
-
convert
- Specified by:
convertin classConverter<ILoggingEvent>
-
setLineSeparator
Sets which lineSeparator to use between events.The following values have special meaning:
nullor 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 customAbbreviatorhas been set throughsetClassNameAbbreviator(Abbreviator).- Parameters:
length- the desired maximum length or-1to 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 customAbbreviatorhas been set throughsetClassNameAbbreviator(Abbreviator).- Returns:
- the abbreviation target length
-
setClassNameAbbreviator
Set a customAbbreviatorused to shorten class names.- Parameters:
abbreviator- theAbbreviatorto use.
-
getClassNameAbbreviator
-
setMaxDepthPerThrowable
public void setMaxDepthPerThrowable(int maxDepthPerThrowable) Set a limit on the number of stackTraceElements per throwable. Use-1to disable the feature and allow for an unlimited depth.- Parameters:
maxDepthPerThrowable- the maximum number of stacktrace elements per throwable or-1to 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-1to disable the feature and allows for any size.- Parameters:
maxLength- the maximum size of the rendered stacktrace or-1for 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-trueto 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
-