public final class StackLocatorUtil extends Object
Modifier and Type | Method and Description |
---|---|
static StackTraceElement |
calcLocation(String fqcnOfLogger) |
static Class<?> |
getCallerClass(Class<?> anchor) |
static Class<?> |
getCallerClass(Class<?> sentinelClass,
Predicate<Class<?>> callerPredicate)
Search for a calling class.
|
static Class<?> |
getCallerClass(int depth) |
static Class<?> |
getCallerClass(String fqcn)
Equivalent to
getCallerClass(String, String) with an empty pkg . |
static Class<?> |
getCallerClass(String fqcn,
String pkg)
Search for a calling class.
|
static 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.
|
static Deque<Class<?>> |
getCurrentStackTrace() |
static StackTraceElement |
getStackTraceElement(int depth) |
public static Class<?> getCallerClass(int depth)
public static StackTraceElement getStackTraceElement(int depth)
public static Class<?> getCallerClass(String fqcn)
getCallerClass(String, String)
with an empty pkg
.public static Class<?> getCallerClass(String fqcn, String pkg)
fqcn
- Root class name whose caller to search for.pkg
- Package name prefix that must be matched after the fqcn
has been found.public static ClassLoader getCallerClassLoader(int depth)
This method returns null
if:
sun.reflect.Reflection.getCallerClass(int)
is not present.sun.reflect.Reflection.getCallerClass(int)
.depth
- The stack frame count to walk.IndexOutOfBoundsException
- if depth is negative.public static Class<?> getCallerClass(Class<?> sentinelClass, Predicate<Class<?>> callerPredicate)
sentinelClass
- Sentinel class at which to begin searchingcallerPredicate
- Predicate checked after the sentinelClass is foundsentinelClass
is found.public static StackTraceElement calcLocation(String fqcnOfLogger)
Copyright © 1999-2022 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.