1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.log4j;
22
23 import org.apache.log4j.spi.LocationInfo;
24
25
26
27
28
29
30
31
32 /***
33 * TODO Add docs
34 * @author vlads
35 * @version $Revision: 1.4 $ ($Author: vlads $)
36 */
37 public class Java14LocationInfo extends LocationInfo {
38
39 /***
40 * Caller's line number.
41 */
42 transient String lineNumber;
43
44 /***
45 * Caller's file name.
46 */
47 transient String fileName;
48
49 /***
50 * Caller's fully qualified class name.
51 */
52 transient String className;
53
54 /***
55 * Caller's method name.
56 */
57 transient String methodName;
58
59 public final static String NA = "?";
60
61 public static long callCount;
62
63 public Java14LocationInfo(Throwable t, String fqnOfCallingClass) {
64 super(null, null);
65 if (t == null) {
66 return;
67 }
68 callCount ++;
69 StackTraceElement[] ste = t.getStackTrace();
70 boolean found = false;
71 for (int i = 0; i < ste.length; i++ ) {
72 if (ste[i].getClassName().equals(fqnOfCallingClass)) {
73 found = true;
74 } else if (found) {
75 StackTraceElement e = ste[i];
76 this.lineNumber = new Integer(e.getLineNumber()).toString();
77 this.fileName = e.getFileName();
78 this.methodName = e.getMethodName();
79 this.className = e.getClassName();
80 return;
81 }
82 }
83 this.lineNumber = NA;
84 this.fileName = NA;
85 this.methodName = NA;
86 this.className = NA;
87 }
88
89 /***
90 * @return Returns the className.
91 */
92 public String getClassName() {
93 return className;
94 }
95 /***
96 * @return Returns the fileName.
97 */
98 public String getFileName() {
99 return fileName;
100 }
101 /***
102 * @return Returns the lineNumber.
103 */
104 public String getLineNumber() {
105 return lineNumber;
106 }
107 /***
108 * @return Returns the methodName.
109 */
110 public String getMethodName() {
111 return methodName;
112 }
113 }