Class ExceptionResolver
- java.lang.Object
-
- org.apache.logging.log4j.layout.template.json.resolver.ExceptionResolver
-
- All Implemented Interfaces:
EventResolver
,TemplateResolver<LogEvent>
- Direct Known Subclasses:
ExceptionRootCauseResolver
public class ExceptionResolver extends Object implements EventResolver
Exception resolver.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 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 usingstackTraceElementTemplate
andsetStackTraceElementTemplateUri
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": ">", "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:
JsonTemplateLayout.Builder.getTruncatedStringSuffix()
,JsonTemplateLayoutDefaults.getTruncatedStringSuffix()
,JsonTemplateLayout.Builder.getStackTraceElementTemplate()
,JsonTemplateLayoutDefaults.getStackTraceElementTemplate()
,JsonTemplateLayout.Builder.getStackTraceElementTemplateUri()
,JsonTemplateLayoutDefaults.getStackTraceElementTemplateUri()
,ExceptionRootCauseResolver
,StackTraceElementResolver
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isResolvable()
Indicates if the resolver if applicable at all.boolean
isResolvable(LogEvent logEvent)
Indicates if the resolver if applicable for the givenvalue
.void
resolve(LogEvent logEvent, JsonWriter jsonWriter)
Resolves the givenvalue
using the providedJsonWriter
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.logging.log4j.layout.template.json.resolver.TemplateResolver
isFlattening, resolve
-
-
-
-
Method Detail
-
isResolvable
public boolean isResolvable()
Description copied from interface:TemplateResolver
Indicates 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:
isResolvable
in interfaceTemplateResolver<LogEvent>
-
isResolvable
public boolean isResolvable(LogEvent logEvent)
Description copied from interface:TemplateResolver
Indicates 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:
isResolvable
in interfaceTemplateResolver<LogEvent>
-
resolve
public void resolve(LogEvent logEvent, JsonWriter jsonWriter)
Description copied from interface:TemplateResolver
Resolves the givenvalue
using the providedJsonWriter
.- Specified by:
resolve
in interfaceTemplateResolver<LogEvent>
-
-