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 theStackTraceElementreturned byLogEvent.getSource().Note that this resolver is toggled by
locationInfoEnabledlayout configuration, which is by default populated fromlog4j.layout.jsonTemplate.locationInfoEnabledsystem 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 EventResolverCLASS_NAME_RESOLVERprivate static EventResolverFILE_NAME_RESOLVERprivate EventResolverinternalResolverprivate static EventResolverLINE_NUMBER_RESOLVERprivate booleanlocationInfoEnabledprivate static EventResolverMETHOD_NAME_RESOLVERprivate static EventResolverNULL_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 EventResolvercreateInternalResolver(EventResolverContext context, TemplateResolverConfig config)(package private) static java.lang.StringgetName()booleanisResolvable()Indicates 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, 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: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
public boolean isResolvable(LogEvent logEvent)
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
public void resolve(LogEvent logEvent, JsonWriter jsonWriter)
Description copied from interface:TemplateResolverResolves the givenvalueusing the providedJsonWriter.- Specified by:
resolvein interfaceTemplateResolver<LogEvent>
-
-