Top Description Fields Constructors Methods
org.apache.logging.log4j.util

public final Class StackLocatorUtil

extends Object
Class Inheritance
Annotations
@InternalApi
Imports
java.util.Deque, .NoSuchElementException, java.util.function.Predicate, org.apache.logging.log4j.status.StatusLogger

Consider this class private. Provides various methods to determine the caller class.

Field Summary

Modifier and TypeField and Description
private static volatile boolean
private static StackLocator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static StackTraceElement
calcLocation(final String fqcnOfLogger)

public static Class<?>
getCallerClass(final int depth)

public static Class<?>
getCallerClass(final String fqcn)

Equivalent to getCallerClass(String, String) with an empty pkg.

public static Class<?>

Returns:

The caller class that was matched, or null if one could not be located.
getCallerClass
(final String
Root class name whose caller to search for.
fqcn
,
final String
Package name prefix that must be matched after the fqcn has been found.
pkg
)

Search for a calling class.

public static Class<?>

Returns:

the first matching class after sentinelClass is found.
getCallerClass
(final Class<?>
Sentinel class at which to begin searching
sentinelClass
,
final Predicate<Class<?>>
Predicate checked after the sentinelClass is found
callerPredicate
)

Search for a calling class.

public static Class<?>
getCallerClass(final Class<?> anchor)

public static ClassLoader

Returns:

A class or null.
getCallerClassLoader
(final int
The stack frame count to walk.
depth
)

Gets the ClassLoader of the class that called this method at the location up the call stack by the given stack frame depth.

public static Deque<Class<?>>
public static StackTraceElement
getStackTraceElement(final int depth)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorLoggedback to summary
private static volatile boolean errorLogged
stackLocatorback to summary
private static StackLocator stackLocator

Constructor Detail

StackLocatorUtilback to summary
private StackLocatorUtil()

Method Detail

calcLocationback to summary
public static StackTraceElement calcLocation(final String fqcnOfLogger)
getCallerClassback to summary
public static Class<?> getCallerClass(final int depth)
Annotations
@PerformanceSensitive
getCallerClassback to summary
public static Class<?> getCallerClass(final String fqcn)

Equivalent to getCallerClass(String, String) with an empty pkg.

Annotations
@PerformanceSensitive
getCallerClassback to summary
public static Class<?> getCallerClass(final String fqcn, final String pkg)

Search for a calling class.

Parameters
fqcn:String

Root class name whose caller to search for.

pkg:String

Package name prefix that must be matched after the fqcn has been found.

Returns:Class<?>

The caller class that was matched, or null if one could not be located.

Annotations
@PerformanceSensitive
getCallerClassback to summary
public static Class<?> getCallerClass(final Class<?> sentinelClass, final Predicate<Class<?>> callerPredicate)

Search for a calling class.

Parameters
sentinelClass:Class<?>

Sentinel class at which to begin searching

callerPredicate:Predicate<Class<?>>

Predicate checked after the sentinelClass is found

Returns:Class<?>

the first matching class after sentinelClass is found.

Annotations
@PerformanceSensitive
getCallerClassback to summary
public static Class<?> getCallerClass(final Class<?> anchor)
Annotations
@PerformanceSensitive
getCallerClassLoaderback to summary
public static ClassLoader getCallerClassLoader(final 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 null if:

  • 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:int

The stack frame count to walk.

Returns:ClassLoader

A class or null.

Annotations
@PerformanceSensitive
Exceptions
IndexOutOfBoundsException:
if depth is negative.
getCurrentStackTraceback to summary
public static Deque<Class<?>> getCurrentStackTrace()
Annotations
@PerformanceSensitive
getStackTraceElementback to summary
public static StackTraceElement getStackTraceElement(final int depth)