public class ExceptionResolver extends Object implements EventResolver
Note that this resolver is toggled by stackTraceEnabled
layout configuration, which is by default populated from log4j.layout.jsonTemplate.stackTraceEnabled
system property.
config = field , [ stringified ] , [ stackTrace ]
field = "field" -> ( "className" | "message" | "stackTrace" )
stackTrace = "stackTrace" -> (
[ stringified ]
, [ elementTemplate ]
)
stringified = "stringified" -> ( boolean | truncation )
truncation = "truncation" -> (
[ suffix ]
, [ pointMatcherStrings ]
, [ pointMatcherRegexes ]
)
suffix = "suffix" -> string
pointMatcherStrings = "pointMatcherStrings" -> string[]
pointMatcherRegexes = "pointMatcherRegexes" -> string[]
elementTemplate = "elementTemplate" -> object
stringified is set to false by default.
stringified at the root level is deprecated in favor of
stackTrace.stringified, which has precedence if both are provided.
pointMatcherStrings and pointMatcherRegexes enable the truncation of stringified stack traces after the given matching point. If both parameters are provided, pointMatcherStrings will be checked first.
If a stringified stack trace truncation takes place, it will be indicated with suffix, which by default is set to the configured truncatedStringSuffix in the layout, unless explicitly provided.
elementTemplate is an object describing the template to be used
while resolving the StackTraceElement array. If stringified
is set to true, elementTemplate will be discarded. By
default, elementTemplate is set to null and rather
populated from the layout configuration. That is, the stack trace element
template can also be provided using stackTraceElementTemplate
and setStackTraceElementTemplateUri
layout configuration parameters. The template to be employed is determined
in the following order:
See StackTraceElementResolver
for the list of available resolvers in a stack trace element template.
{
"$resolver": "exception",
"field": "className"
}
Resolve the stack trace into a list of StackTraceElement objects:
{
"$resolver": "exception",
"field": "stackTrace"
}
Resolve the stack trace into a string field:
{
"$resolver": "exception",
"field": "stackTrace",
"stackTrace": {
"stringified": true
}
}
Resolve the stack trace into a string field
such that the content will be truncated after the given point matcher:
{
"$resolver": "exception",
"field": "stackTrace",
"stackTrace": {
"stringified": {
"truncation": {
"suffix": ">",
"pointMatcherStrings": ["at javax.servlet.http.HttpServlet.service"]
}
}
}
}
Resolve the stack trace into an object described by the provided stack trace
element template:
{
"$resolver": "exception",
"field": "stackTrace",
"stackTrace": {
"elementTemplate": {
"class": {
"$resolver": "stackTraceElement",
"field": "className"
},
"method": {
"$resolver": "stackTraceElement",
"field": "methodName"
},
"file": {
"$resolver": "stackTraceElement",
"field": "fileName"
},
"line": {
"$resolver": "stackTraceElement",
"field": "lineNumber"
}
}
}
}
JsonTemplateLayout.Builder#getTruncatedStringSuffix(),
JsonTemplateLayoutDefaults.getTruncatedStringSuffix(),
JsonTemplateLayout.Builder#getStackTraceElementTemplate(),
JsonTemplateLayoutDefaults.getStackTraceElementTemplate(),
JsonTemplateLayout.Builder#getStackTraceElementTemplateUri(),
JsonTemplateLayoutDefaults.getStackTraceElementTemplateUri(),
ExceptionRootCauseResolver,
StackTraceElementResolver| Modifier and Type | Method and Description |
|---|---|
boolean |
isResolvable()
Indicates if the resolver if applicable at all.
|
boolean |
isResolvable(LogEvent logEvent)
Indicates if the resolver if applicable for the given
value. |
void |
resolve(LogEvent logEvent,
JsonWriter jsonWriter)
Resolves the given
value using the provided JsonWriter. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisFlattening, resolvepublic boolean isResolvable()
TemplateResolverFor instance, the source line resolver can be short-circuited using this check if the location information is disabled in the layout configuration.
isResolvable in interface TemplateResolver<LogEvent>public boolean isResolvable(LogEvent logEvent)
TemplateResolvervalue.
For instance, the stack trace resolver can be short-circuited using this check if the stack traces are disabled in the layout configuration.
isResolvable in interface TemplateResolver<LogEvent>public void resolve(LogEvent logEvent, JsonWriter jsonWriter)
TemplateResolvervalue using the provided JsonWriter.resolve in interface TemplateResolver<LogEvent>Copyright © 1999-2022 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.