Class ExceptionResolver
- All Implemented Interfaces:
EventResolver,TemplateResolver<LogEvent>
- Direct Known Subclasses:
ExceptionRootCauseResolver
Note that this resolver is toggled by stackTraceEnabled
layout configuration, which is by default populated from log4j.layout.jsonTemplate.stackTraceEnabled
system property.
Configuration
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 a suffix, which by default is set to the configured truncatedStringSuffix in the layout, unless explicitly provided. Every truncation suffix is prefixed with a newline.
Stringified stack trace truncation operates in Caused by: and Suppressed: label blocks. That is, matchers are executed against each label in isolation.
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:
- elementTemplate provided in the resolver configuration
- stackTraceElementTemplate parameter from layout configuration (the default is populated from log4j.layout.jsonTemplate.stackTraceElementTemplate system property)
- stackTraceElementTemplateUri parameter from layout configuration (the default is populated from log4j.layout.jsonTemplate.stackTraceElementTemplateUri system property)
See StackTraceElementResolver
for the list of available resolvers in a stack trace element template.
Examples
Resolve logEvent.getThrown().getClass().getCanonicalName():
{
"$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": "... [truncated]",
"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"
}
}
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates if the resolver if applicable at all.booleanisResolvable(LogEvent logEvent) Indicates if the resolver if applicable for the givenvalue.voidresolve(LogEvent logEvent, JsonWriter jsonWriter) Resolves the givenvalueusing the providedJsonWriter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.layout.template.json.resolver.TemplateResolver
isFlattening, resolve
-
Method Details
-
isResolvable
public boolean isResolvable()Description copied from interface:TemplateResolverIndicates if the resolver if applicable at all.For instance, the source line resolver can be short-circuited using this check if the location information is disabled in the layout configuration.
- Specified by:
isResolvablein interfaceTemplateResolver<LogEvent>
-
isResolvable
Description copied from interface:TemplateResolverIndicates if the resolver if applicable for the givenvalue.For instance, the stack trace resolver can be short-circuited using this check if the stack traces are disabled in the layout configuration.
- Specified by:
isResolvablein interfaceTemplateResolver<LogEvent>
-
resolve
Description copied from interface:TemplateResolverResolves the givenvalueusing the providedJsonWriter.- Specified by:
resolvein interfaceTemplateResolver<LogEvent>
-