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 java.lang.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" }
-
-
Field Summary
Fields Modifier and Type Field Description private static EventResolver
CLASS_NAME_RESOLVER
private static EventResolver
FILE_NAME_RESOLVER
private EventResolver
internalResolver
private static EventResolver
LINE_NUMBER_RESOLVER
private boolean
locationInfoEnabled
private static EventResolver
METHOD_NAME_RESOLVER
private static EventResolver
NULL_RESOLVER
-
Constructor Summary
Constructors Constructor Description SourceResolver(EventResolverContext context, TemplateResolverConfig config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static EventResolver
createInternalResolver(EventResolverContext context, TemplateResolverConfig config)
(package private) static java.lang.String
getName()
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
-
-
-
-
Field Detail
-
NULL_RESOLVER
private static final EventResolver NULL_RESOLVER
-
CLASS_NAME_RESOLVER
private static final EventResolver CLASS_NAME_RESOLVER
-
FILE_NAME_RESOLVER
private static final EventResolver FILE_NAME_RESOLVER
-
LINE_NUMBER_RESOLVER
private static final EventResolver LINE_NUMBER_RESOLVER
-
METHOD_NAME_RESOLVER
private static final EventResolver METHOD_NAME_RESOLVER
-
locationInfoEnabled
private final boolean locationInfoEnabled
-
internalResolver
private final EventResolver internalResolver
-
-
Constructor Detail
-
SourceResolver
SourceResolver(EventResolverContext context, TemplateResolverConfig config)
-
-
Method Detail
-
createInternalResolver
private static EventResolver createInternalResolver(EventResolverContext context, TemplateResolverConfig config)
-
getName
static java.lang.String getName()
-
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>
-
-