(file) Return to Tracer.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 kumpf 1.1.2.1 //%/////////////////////////////////////////////////////////////////////////////
  2               //
  3               // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
  4               // The Open Group, Tivoli Systems
  5               //
  6               // Permission is hereby granted, free of charge, to any person obtaining a copy
  7               // of this software and associated documentation files (the "Software"), to
  8               // deal in the Software without restriction, including without limitation the
  9               // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10               // sell copies of the Software, and to permit persons to whom the Software is
 11               // furnished to do so, subject to the following conditions:
 12               //
 13               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14               // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15               // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16               // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17               // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18               // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19               // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20               // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21               //
 22 kumpf 1.1.2.1 //==============================================================================
 23               //
 24               // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
 25               //
 26               // Modified By:
 27               //
 28               //%/////////////////////////////////////////////////////////////////////////////
 29               
 30               #ifndef Pegasus_Tracer_h
 31               #define Pegasus_Tracer_h
 32               
 33               #include <stdarg.h>
 34 kumpf 1.1.2.2 #include <fstream>
 35 kumpf 1.1.2.1 #include <Pegasus/Common/String.h>
 36               #include <Pegasus/Common/System.h>
 37               #include <Pegasus/Common/Logger.h>
 38               #include <Pegasus/Common/TraceComponents.h>
 39               #include <Pegasus/Common/TraceFileHandler.h>
 40               
 41               
 42               PEGASUS_NAMESPACE_BEGIN
 43               
 44               /** Tracer implements tracing of messages to a defined file
 45                */
 46               
 47               class PEGASUS_COMMON_LINKAGE Tracer
 48               {
 49               public:
 50               
 51                   /** Levels of trace
 52                       Trace messages are written to the trace file only if they are at or
 53                       above a given trace level
 54                       LEVEL1 - Function Entry/Exit
 55                       LEVEL2 - Basic flow trace messages, low data detail
 56 kumpf 1.1.2.1         LEVEL3 - Inter-function logic flow, medium data detail
 57                       LEVEL4 - High data detail
 58                    */
 59                   static const Uint32 LEVEL1;
 60                   static const Uint32 LEVEL2;
 61                   static const Uint32 LEVEL3;
 62                   static const Uint32 LEVEL4;
 63                   
 64                   // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace 
 65                   // interfaces. If defined the interfaces map to empty functions
 66                   
 67                   #ifdef PEGASUS_REMOVE_TRACE
 68                       
 69                       inline static void trace(
 70                           const Uint32 traceComponent,
 71                           const Uint32 traceLevel,
 72                           const char *fmt,
 73                           ...)
 74                       {
 75                           // empty function
 76                       }
 77 kumpf 1.1.2.1         
 78                       inline static void trace(
 79                           const char*  fileName,
 80                           const Uint32 lineNum,
 81                           const Uint32 traceComponent,
 82                           const Uint32 traceLevel,
 83                           const char* fmt,
 84                           ...)
 85                       {
 86                           // empty function
 87                       }
 88               
 89                   #else
 90                       
 91                       /** Traces the given message 
 92                           @param    traceComponent  component being traced
 93                           @param    traceLevel      trace level of the trace message
 94                           @param    *fmt            printf style format string
 95                           @param    ...             variable argument list
 96                        */
 97                       inline static void trace(
 98 kumpf 1.1.2.1             const Uint32 traceComponent,
 99                           const Uint32 traceLevel,
100                           const char *fmt,
101                           ...)
102                       {
103                           va_list argList;
104                       
105                           va_start(argList,fmt);
106                           _trace(traceComponent,traceLevel,fmt,argList); 
107                           va_end(argList);
108                       }
109                       
110                       /** Traces the given message. Overloaded to include the filename and 
111               	    the line number of trace origin. 
112                           @param    fileName        filename of the trace originator
113                           @param    lineNum         line number of the trace originator
114                           @param    traceComponent  component being traced
115                           @param    traceLevel      trace level of the trace message
116                           @param    *fmt            printf style format string
117                           @param    ...             variable argument list
118                        */
119 kumpf 1.1.2.1         inline static void trace(
120                           const char* fileName,
121                           const Uint32 lineNum,
122                           const Uint32 traceComponent,
123                           const Uint32 traceLevel,
124                           const char* fmt,
125                           ...)
126                       {
127                           va_list argList;
128                       
129                           va_start(argList,fmt);
130                           _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList); 
131                           va_end(argList);
132                       }
133                       
134                   #endif 
135               
136                   // End of PEGASUS_REMOVE_TRACE
137                       
138                   /** Traces method entry. 
139                       @param    fileName        filename of the trace originator
140 kumpf 1.1.2.1         @param    lineNum         line number of the trace originator
141                       @param    traceComponent  component being traced
142                       @param    methodName      method being traced
143                    */
144                   inline static void traceEnter(
145                       const char* fileName,
146                       const Uint32 lineNum,
147                       const Uint32 traceComponent,
148                       const char* methodName)
149                   {
150                       _traceEnter( fileName, lineNum, traceComponent, "%s %s",
151                   	    _FUNC_ENTER_MSG, methodName);
152                   }
153                   
154                   /** Traces method exit. 
155                       @param    fileName        filename of the trace originator
156                       @param    lineNum         line number of the trace originator
157                       @param    traceComponent  component being traced
158                       @param    methodName      method being traced
159                    */
160                   inline static void traceExit(
161 kumpf 1.1.2.1         const char* fileName,
162                       const Uint32 lineNum,
163                       const Uint32 traceComponent,
164                       const char* methodName)
165                   {
166                       _traceExit( fileName, lineNum, traceComponent, "%s %s",
167                   	    _FUNC_EXIT_MSG, methodName);
168                   }
169               
170                   /** Set the trace file to the given file
171                       @param    traceFile       full path of the trace file
172                       @return   0               if the filepath is valid 
173                                 1               if an error occurs while opening the file in
174                                                 append mode
175                    */
176                   static Uint32 setTraceFile(const char* traceFile);
177               
178                   /** Set the trace level to the given level
179                       @param    traceLevel      trace level to be set
180                       @return   0               if trace level is valid
181                                 1               if trace level is invalid
182 kumpf 1.1.2.1      */
183                   static Uint32 setTraceLevel(const Uint32 traceLevel);
184               
185                  /** Set components to be traced
186                      @param    traceComponents list of components to be traced, components 
187                                should be separated by ','
188                   */
189                   static void setTraceComponents(String traceComponents);
190               
191               private:
192               
193                   static const char   _COMPONENT_SEPARATOR;
194                   static const Uint32 _NUM_COMPONENTS;
195 kumpf 1.1.2.3     static const Uint32 _STRLEN_MAX_UNSIGNED_INT;
196 kumpf 1.1.2.1     Boolean*            _traceComponentMask;
197                   Uint32              _traceLevelMask;
198                   TraceFileHandler*   _traceHandler;
199                   static Tracer*      _tracerInstance;
200               
201                   // Message Strings for fucntion Entry and Exit
202                   static const char _FUNC_ENTER_MSG[]; 
203                   static const char _FUNC_EXIT_MSG[]; 
204               
205                   // Message Strings for Logger
206                   static const char _LOG_MSG1[]; 
207                   static const char _LOG_MSG2[]; 
208               
209                   // Checks if trace is enabled for the given component and trace level
210                   // @param    traceComponent  component being traced
211                   // @param    traceLevel      level of the trace message
212                   // @return   0               if the component and level are not enabled 
213                   //           1               if the component and level are enabled 
214                   static Boolean _isTraceEnabled(
215               	const Uint32 traceComponent,
216               	const Uint32 traceLevel);
217 kumpf 1.1.2.1 
218                   // Traces the given message 
219                   //  @param    traceComponent  component being traced
220                   //  @param    traceLevel      level of the trace message
221                   //  @param    *fmt            printf style format string
222                   //  @param    argList         variable argument list
223                   static void _trace(
224               	const Uint32 traceComponent,
225                       const Uint32 traceLevel,
226               	const char* fmt,
227               	va_list argList);
228               
229                   // Traces the given message. Overloaded to include the file name and the
230                   // line number as one of the parameters.
231                   // @param    traceComponent  component being traced
232                   // @param    traceLevel      level of the trace message
233                   // @param    message         message header (file name:line number)
234                   // @param    *fmt            printf style format string
235                   // @param    argList         variable argument list
236                   static void _trace(
237               	const char* fileName,
238 kumpf 1.1.2.1 	const Uint32 lineNum,
239               	const Uint32 traceComponent,
240                       const Uint32 traceLevel,
241               	const char* fmt,
242               	va_list argList);
243               
244                   // Called by all the trace interfaces to log message to the 
245                   // trace file
246                   // @param    fileName        filename of the trace originator
247                   // @param    lineNum         line number of the trace originator
248                   // @param    traceComponent  component being traced
249                   // @param    *fmt            printf style format string
250                   // @param    argList         variable argument list
251                   static void _trace(
252               	const Uint32 traceComponent,
253               	const char* message,
254               	const char* fmt,
255               	va_list argList);
256               
257                   // Traces method enter
258                   // @param    fileName        filename of the trace originator
259 kumpf 1.1.2.1     // @param    lineNum         line number of the trace originator
260                   // @param    traceComponent  component being traced
261                   // @param    *fmt            printf style format string
262                   // @param    ...             variable argument list
263                   static void _traceEnter(
264               	const char* fileName,
265               	const Uint32 lineNum,
266               	const Uint32 traceComponent,
267               	const char* fmt,
268               	...);
269               
270                   // Traces method exit
271                   // @param    fileName        filename of the trace originator
272                   // @param    traceComponent  component being traced
273                   // @param    *fmt            printf style format string
274                   // @param    ...             variable argument list
275                   static void _traceExit(
276               	const char* fileName,
277               	const Uint32 lineNum,
278               	const Uint32 traceComponent,
279               	const char* fmt,
280 kumpf 1.1.2.1 	...);
281               
282                   // Tracer constructor
283                   // Constructor is private to prevent construction of Tracer objects
284                   // Single Instance of Tracer is maintained for each process.
285                   Tracer();
286               
287                   //   Tracer destructor
288                   ~Tracer();
289               
290                   // Returns the Singleton instance of the Tracer
291                   // @return   Tracer*  Instance of Tracer 
292                   static Tracer* _getInstance();
293               };
294               
295               // Define the macros for method entry/exit
296               #ifdef PEGASUS_REMOVE_TRACE
297                   #define PEG_FUNC_ENTER(traceComponent,methodName) 
298                   #define PEG_FUNC_EXIT(traceComponent,methodName) 
299               #else
300                   /** Macro for tracing method entry
301 kumpf 1.1.2.1         @param    traceComponent  component being traced
302                       @param    methodName      name of the method
303                    */
304                   #define PEG_FUNC_ENTER(traceComponent,methodName) \
305               	Tracer::traceEnter(__FILE__, __LINE__,traceComponent,methodName)
306               
307                   /** Macro for tracing method exit
308                       @param    traceComponent  component being traced
309                       @param    methodName      name of the method
310                    */
311                   #define PEG_FUNC_EXIT(traceComponent,methodName) \
312               	Tracer::traceExit(__FILE__,__LINE__,traceComponent,methodName)
313               #endif
314               
315               PEGASUS_NAMESPACE_END
316               #endif /* Pegasus_Tracer_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2