public class LocationInfo extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
(package private) String |
className
Caller's fully qualified class name.
|
(package private) String |
fileName
Caller's file name.
|
String |
fullInfo
All available caller information, in the format
fully.qualified.classname.of.caller.methodName(Filename.java:line) |
private static Method |
getClassNameMethod |
private static Method |
getFileNameMethod |
private static Method |
getLineNumberMethod |
private static Method |
getMethodNameMethod |
private static Method |
getStackTraceMethod |
(package private) static boolean |
inVisualAge |
(package private) String |
lineNumber
Caller's line number.
|
(package private) String |
methodName
Caller's method name.
|
static 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 PrintWriter |
pw |
(package private) static long |
serialVersionUID |
private static StringWriter |
sw |
Constructor and Description |
---|
LocationInfo(String file,
String classname,
String method,
String line)
Create new instance.
|
LocationInfo(Throwable t,
String fqnOfCallingClass)
Instantiate location information based on a Throwable.
|
Modifier and Type | Method and Description |
---|---|
private static void |
appendFragment(StringBuffer buf,
String fragment)
Appends a location fragment to a buffer to build the
full location info.
|
String |
getClassName()
Return the fully qualified class name of the caller making the
logging request.
|
String |
getFileName()
Return the file name of the caller.
|
String |
getLineNumber()
Returns the line number of the caller.
|
String |
getMethodName()
Returns the method name of the caller.
|
transient String lineNumber
transient String methodName
public String fullInfo
fully.qualified.classname.of.caller.methodName(Filename.java:line)
private static StringWriter sw
private static PrintWriter pw
private static Method getStackTraceMethod
private static Method getClassNameMethod
private static Method getMethodNameMethod
private static Method getFileNameMethod
private static Method getLineNumberMethod
public static final String NA
NA
is returned. Current value of this string
constant is ?.static final long serialVersionUID
public static final LocationInfo NA_LOCATION_INFO
static boolean inVisualAge
public LocationInfo(Throwable t, String fqnOfCallingClass)
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.
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.public LocationInfo(String file, String classname, String method, String line)
file
- source file nameclassname
- class namemethod
- methodline
- source line numberprivate static final void appendFragment(StringBuffer buf, String fragment)
buf
- StringBuffer to receive content.fragment
- fragment of location (class, method, file, line),
if null the value of NA will be appended.public String getClassName()
public String getFileName()
This information is not always available.
public String getLineNumber()
This information is not always available.
public String getMethodName()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses