Class SourceResolver
- java.lang.Object
-
- org.apache.logging.log4j.layout.template.json.resolver.SourceResolver
-
- All Implemented Interfaces:
EventResolver
,TemplateResolver<LogEvent>
public final class SourceResolver extends Object implements EventResolver
Resolver for theStackTraceElement
returned byLogEvent.getSource()
.Note that this resolver is toggled by
locationInfoEnabled
layout configuration, which is by default populated fromlog4j.layout.jsonTemplate.locationInfoEnabled
system property.Configuration
config = "field" -> ( "className" | "fileName" | "methodName" | "lineNumber" )
Examples
Resolve the line number:{ "$resolver": "source", "field": "lineNumber" }
-
-
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>
-
-