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
24
25
26
27
28
29
30
31 import org.apache.log4j.Logger;
32 import org.apache.log4j.spi.LocationInfo;
33
34
35 /***
36 * TODO Add docs
37 * @author vlads
38 * @version $Revision: 1.3 $ ($Author: vlads $)
39 */
40 public class LocationInfoPerformance extends PerformanceCase {
41 /***
42 * logger.
43 */
44 protected final Logger log = Logger.getLogger(this.getClass());
45
46 public interface PseudoLogger {
47 public abstract LocationInfo getLocationInfo();
48 }
49
50 public class Log4jWay implements PseudoLogger {
51
52 protected final String fqnOfCategoryClass = this.getClass().getName();
53
54 public LocationInfo getLocationInfo() {
55 return new LocationInfo(new Throwable(), fqnOfCategoryClass);
56 }
57 }
58
59 public class Java14Way implements PseudoLogger {
60
61 protected final String fqnOfCategoryClass = this.getClass().getName();
62
63 public LocationInfo getLocationInfo() {
64 return new Java14LocationInfo(new Throwable(), fqnOfCategoryClass);
65 }
66 }
67
68 public class Java13CompatibleWay implements PseudoLogger {
69
70 protected final String fqnOfCategoryClass = this.getClass().getName();
71
72 public LocationInfo getLocationInfo() {
73 return new WrapedLocationInfo(new Throwable(), fqnOfCategoryClass);
74 }
75 }
76
77 PseudoLogger aLog;
78
79 public void setUp() throws Exception {
80 super.setUp();
81
82 if (subcase.equalsIgnoreCase("Java14Way")) {
83 aLog = new Java14Way();
84 name = "Java14Way";
85 } else {
86 aLog = new Log4jWay();
87 name = "Log4jWay";
88 }
89 StackTraceElement[] ste = (new Throwable()).getStackTrace();
90 name = name + " Stack:" + ste.length;
91 LocationInfo li = aLog.getLocationInfo();
92 log.debug("Verify: " + li.getMethodName() + " line: "+ li.getLineNumber());
93 }
94
95 public void tearDown() throws Exception {
96 log.debug("Java14LocationInfo called:" + Java14LocationInfo.callCount);
97 }
98
99 public void execute() {
100 LocationInfo li = aLog.getLocationInfo();
101 li.getFileName();
102 li.getLineNumber();
103 li.getClassName();
104 li.getMethodName();
105 }
106 }