1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.log4j;
22  /*
23   * Created on 21.11.2004
24   *
25   * Contributing Author(s):
26   *
27   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
28   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
29   */
30  
31  import org.apache.log4j.Logger;
32  import org.apache.log4j.spi.LocationInfo;
33  //import org.apache.log4j.spi.Java14LocationInfoX;
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 }