View Javadoc

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.ext;
22  
23  import net.sf.jour.rt.agent.ProfilerEvent;
24  
25  import org.apache.log4j.Category;
26  import org.apache.log4j.Priority;
27  import org.apache.log4j.spi.LocationInfo;
28  import org.apache.log4j.spi.LoggingEvent;
29  /***
30   * Convers Jour Event to printable log4j events.
31   *
32   * Created on 06.12.2004
33   * Contributing Author(s):
34   *
35   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
36   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
37   *
38   * @author vlads
39   * @version $Revision: 1.1 $ ($Author: vlads $)  $Date: 2004/12/07 09:05:03 $
40   */
41  public class LoggingProfilerEvent extends LoggingEvent {
42      
43      private ProfilerEvent wrapedProfilerEvent;
44      
45      private transient LocationInfo locationInfo;
46      
47      public LoggingProfilerEvent(String fqnOfCategoryClass, Category logger,
48  		      Priority level, ProfilerEvent profilerEvent) {
49          super(fqnOfCategoryClass, logger, 
50                  profilerEvent.getTimestampLong(),
51                  level, profilerEvent.getType(), profilerEvent.getThrowable());
52          wrapedProfilerEvent = profilerEvent;
53      }
54      
55      //public LoggingProfilerEvent(ProfilerEvent profilerEvent) {
56          
57      //}
58      
59      public String getLoggerName() {
60          return wrapedProfilerEvent.getClassName();
61      }
62      
63      
64      public String getThreadName() {
65          return wrapedProfilerEvent.getThreadName();
66      }
67      
68      public class ExtLocationInfo extends LocationInfo {
69          
70          public ExtLocationInfo() {
71              super(null, null);
72          }
73          
74          public final static String NA = "?";
75          
76          /***
77           * @return Returns the className.
78           */
79          public String getClassName() {
80              return wrapedProfilerEvent.getClassName();
81          }
82          /***
83           * @return Returns the fileName.
84           */
85          public String getFileName() {
86              return NA;
87          }
88          /***
89           * @return Returns the lineNumber.
90           */
91          public String getLineNumber() {
92              return NA;
93          }
94          /***
95           * @return Returns the methodName.
96           */
97          public String getMethodName() {
98              return wrapedProfilerEvent.getMethodName();
99          }
100     }
101     
102     public LocationInfo getLocationInformation() {
103         if (locationInfo == null) {
104             locationInfo = new ExtLocationInfo();
105         }
106         return locationInfo;
107     }
108 
109 }