Class LocationInfo

java.lang.Object
com.log4rich.util.LocationInfo

public class LocationInfo extends Object
Captures location information about where a log event occurred. This includes class name, method name, line number, and filename.
  • Constructor Details

    • LocationInfo

      public LocationInfo(String className, String methodName, String fileName, int lineNumber)
      Creates a new LocationInfo with the specified location details.
      Parameters:
      className - the fully qualified class name
      methodName - the method name
      fileName - the source file name
      lineNumber - the line number in the source file
  • Method Details

    • getCaller

      public static LocationInfo getCaller(int skipFrames)
      Create LocationInfo by analyzing the current stack trace.
      Parameters:
      skipFrames - Number of stack frames to skip (typically 2-3 for logger calls)
      Returns:
      LocationInfo object or null if unable to determine
    • getTruncatedClassName

      public String getTruncatedClassName()
      Get truncated class name (e.g., c.e.MyClass).
      Returns:
      Truncated class name
    • getClassName

      public String getClassName()
      Gets the simple class name (without package).
      Returns:
      the simple class name
    • getFullClassName

      public String getFullClassName()
      Gets the fully qualified class name.
      Returns:
      the full class name including package
    • getMethodName

      public String getMethodName()
      Gets the method name where the log event occurred.
      Returns:
      the method name
    • getFileName

      public String getFileName()
      Gets the source file name.
      Returns:
      the source file name
    • getLineNumber

      public int getLineNumber()
      Gets the line number where the log event occurred.
      Returns:
      the line number
    • toString

      public String toString()
      Returns a string representation of the location information.
      Overrides:
      toString in class Object
      Returns:
      formatted string containing class.method(file:line)