Class LocationInfo

  • All Implemented Interfaces:
    java.io.Serializable

    public class LocationInfo
    extends java.lang.Object
    implements java.io.Serializable
    The internal representation of caller location information.
    Since:
    0.8.3
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.lang.String className
      Caller's fully qualified class name.
      (package private) java.lang.String fileName
      Caller's file name.
      java.lang.String fullInfo
      All available caller information, in the format fully.qualified.classname.of.caller.methodName(Filename.java:line)
      private static java.lang.reflect.Method getClassNameMethod  
      private static java.lang.reflect.Method getFileNameMethod  
      private static java.lang.reflect.Method getLineNumberMethod  
      private static java.lang.reflect.Method getMethodNameMethod  
      private static java.lang.reflect.Method getStackTraceMethod  
      (package private) static boolean inVisualAge  
      (package private) java.lang.String lineNumber
      Caller's line number.
      (package private) java.lang.String methodName
      Caller's method name.
      static java.lang.String NA
      When location information is not available the constant NA is returned.
      static LocationInfo NA_LOCATION_INFO
      NA_LOCATION_INFO is provided for compatibility with log4j 1.3.
      private static java.io.PrintWriter pw  
      (package private) static long serialVersionUID  
      private static java.io.StringWriter sw  
    • Constructor Summary

      Constructors 
      Constructor Description
      LocationInfo​(java.lang.String file, java.lang.String classname, java.lang.String method, java.lang.String line)
      Create new instance.
      LocationInfo​(java.lang.Throwable t, java.lang.String fqnOfCallingClass)
      Instantiate location information based on a Throwable.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void appendFragment​(java.lang.StringBuffer buf, java.lang.String fragment)
      Appends a location fragment to a buffer to build the full location info.
      java.lang.String getClassName()
      Return the fully qualified class name of the caller making the logging request.
      java.lang.String getFileName()
      Return the file name of the caller.
      java.lang.String getLineNumber()
      Returns the line number of the caller.
      java.lang.String getMethodName()
      Returns the method name of the caller.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lineNumber

        transient java.lang.String lineNumber
        Caller's line number.
      • fileName

        transient java.lang.String fileName
        Caller's file name.
      • className

        transient java.lang.String className
        Caller's fully qualified class name.
      • methodName

        transient java.lang.String methodName
        Caller's method name.
      • fullInfo

        public java.lang.String fullInfo
        All available caller information, in the format fully.qualified.classname.of.caller.methodName(Filename.java:line)
      • sw

        private static java.io.StringWriter sw
      • pw

        private static java.io.PrintWriter pw
      • getStackTraceMethod

        private static java.lang.reflect.Method getStackTraceMethod
      • getClassNameMethod

        private static java.lang.reflect.Method getClassNameMethod
      • getMethodNameMethod

        private static java.lang.reflect.Method getMethodNameMethod
      • getFileNameMethod

        private static java.lang.reflect.Method getFileNameMethod
      • getLineNumberMethod

        private static java.lang.reflect.Method getLineNumberMethod
      • NA

        public static final java.lang.String NA
        When location information is not available the constant NA is returned. Current value of this string constant is ?.
        See Also:
        Constant Field Values
      • NA_LOCATION_INFO

        public static final LocationInfo NA_LOCATION_INFO
        NA_LOCATION_INFO is provided for compatibility with log4j 1.3.
        Since:
        1.2.15
      • inVisualAge

        static boolean inVisualAge
    • Constructor Detail

      • LocationInfo

        public LocationInfo​(java.lang.Throwable t,
                            java.lang.String fqnOfCallingClass)
        Instantiate location information based on a Throwable. We expect the Throwable t, to be in the format
                java.lang.Throwable
                ...
                  at org.apache.log4j.PatternLayout.format(PatternLayout.java:413)
                  at org.apache.log4j.FileAppender.doAppend(FileAppender.java:183)
                at org.apache.log4j.Category.callAppenders(Category.java:131)
                at org.apache.log4j.Category.log(Category.java:512)
                at callers.fully.qualified.className.methodName(FileName.java:74)
                ...
               

        However, we can also deal with JIT compilers that "lose" the location information, especially between the parentheses.

        Parameters:
        t - throwable used to determine location, may be null.
        fqnOfCallingClass - class name of first class considered part of the logging framework. Location will be site that calls a method on this class.
      • LocationInfo

        public LocationInfo​(java.lang.String file,
                            java.lang.String classname,
                            java.lang.String method,
                            java.lang.String line)
        Create new instance.
        Parameters:
        file - source file name
        classname - class name
        method - method
        line - source line number
        Since:
        1.2.15
    • Method Detail

      • appendFragment

        private static final void appendFragment​(java.lang.StringBuffer buf,
                                                 java.lang.String fragment)
        Appends a location fragment to a buffer to build the full location info.
        Parameters:
        buf - StringBuffer to receive content.
        fragment - fragment of location (class, method, file, line), if null the value of NA will be appended.
        Since:
        1.2.15
      • getClassName

        public java.lang.String getClassName()
        Return the fully qualified class name of the caller making the logging request.
      • getFileName

        public java.lang.String getFileName()
        Return the file name of the caller.

        This information is not always available.

      • getLineNumber

        public java.lang.String getLineNumber()
        Returns the line number of the caller.

        This information is not always available.

      • getMethodName

        public java.lang.String getMethodName()
        Returns the method name of the caller.