Package org.apache.logging.log4j.util
Class StackLocatorUtil
- java.lang.Object
-
- org.apache.logging.log4j.util.StackLocatorUtil
-
public final class StackLocatorUtil extends java.lang.ObjectConsider this class private. Provides various methods to determine the caller class.Background
-
-
Field Summary
Fields Modifier and Type Field Description private static booleanerrorLoggedprivate static StackLocatorstackLocator
-
Constructor Summary
Constructors Modifier Constructor Description privateStackLocatorUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StackTraceElementcalcLocation(java.lang.String fqcnOfLogger)static java.lang.Class<?>getCallerClass(int depth)static java.lang.Class<?>getCallerClass(java.lang.Class<?> anchor)static java.lang.Class<?>getCallerClass(java.lang.Class<?> sentinelClass, java.util.function.Predicate<java.lang.Class<?>> callerPredicate)Search for a calling class.static java.lang.Class<?>getCallerClass(java.lang.String fqcn)Equivalent togetCallerClass(String, String)with an emptypkg.static java.lang.Class<?>getCallerClass(java.lang.String fqcn, java.lang.String pkg)Search for a calling class.static java.lang.ClassLoadergetCallerClassLoader(int depth)Gets the ClassLoader of the class that called this method at the location up the call stack by the given stack frame depth.static java.util.Deque<java.lang.Class<?>>getCurrentStackTrace()static java.lang.StackTraceElementgetStackTraceElement(int depth)
-
-
-
Field Detail
-
stackLocator
private static StackLocator stackLocator
-
errorLogged
private static volatile boolean errorLogged
-
-
Method Detail
-
getCallerClass
public static java.lang.Class<?> getCallerClass(int depth)
-
getStackTraceElement
public static java.lang.StackTraceElement getStackTraceElement(int depth)
-
getCallerClass
public static java.lang.Class<?> getCallerClass(java.lang.String fqcn)
Equivalent togetCallerClass(String, String)with an emptypkg.
-
getCallerClass
public static java.lang.Class<?> getCallerClass(java.lang.String fqcn, java.lang.String pkg)Search for a calling class.- Parameters:
fqcn- Root class name whose caller to search for.pkg- Package name prefix that must be matched after thefqcnhas been found.- Returns:
- The caller class that was matched, or null if one could not be located.
-
getCallerClassLoader
public static java.lang.ClassLoader getCallerClassLoader(int depth)
Gets the ClassLoader of the class that called this method at the location up the call stack by the given stack frame depth.This method returns
nullif:sun.reflect.Reflection.getCallerClass(int)is not present.- An exception is caught calling
sun.reflect.Reflection.getCallerClass(int). - Some Class implementations may use null to represent the bootstrap class loader.
- Parameters:
depth- The stack frame count to walk.- Returns:
- A class or null.
- Throws:
java.lang.IndexOutOfBoundsException- if depth is negative.
-
getCallerClass
public static java.lang.Class<?> getCallerClass(java.lang.Class<?> sentinelClass, java.util.function.Predicate<java.lang.Class<?>> callerPredicate)Search for a calling class.- Parameters:
sentinelClass- Sentinel class at which to begin searchingcallerPredicate- Predicate checked after the sentinelClass is found- Returns:
- the first matching class after
sentinelClassis found.
-
getCallerClass
public static java.lang.Class<?> getCallerClass(java.lang.Class<?> anchor)
-
getCurrentStackTrace
public static java.util.Deque<java.lang.Class<?>> getCurrentStackTrace()
-
calcLocation
public static java.lang.StackTraceElement calcLocation(java.lang.String fqcnOfLogger)
-
-