1 karl 1.34 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.24 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.21 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.24 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.27 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.34 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.34 //
|
21 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
|
34 sage 1.4 #include <Pegasus/Common/Config.h>
|
35 mike 1.2 #include <Pegasus/Common/Tracer.h>
|
36 r.kieninger 1.49 #include <Pegasus/Common/TraceFileHandler.h>
37 #include <Pegasus/Common/TraceLogHandler.h>
|
38 kumpf 1.3 #include <Pegasus/Common/Thread.h>
39 #include <Pegasus/Common/System.h>
|
40 sushma.fernandes 1.45 #include <Pegasus/Common/HTTPMessage.h>
|
41 mike 1.2
|
42 r.kieninger 1.49
|
43 mike 1.2 PEGASUS_USING_STD;
44
45 PEGASUS_NAMESPACE_BEGIN
46
|
47 r.kieninger 1.49
48 // Defines the value values for trace facilities
49 // Keep the TRACE_FACILITY_LIST in sync with the TRACE_FACILITY_INDEX,
50 // so that the index matches the according string in the list.
51 char const* Tracer::TRACE_FACILITY_LIST[] =
52 {
53 "File",
54 "Log",
55 0
56 };
57
58
|
59 mike 1.2 // Set the trace levels
60 // These levels will be compared against a trace level mask to determine
|
61 chip 1.20 // if a specific trace level is enabled
|
62 mike 1.2
|
63 marek 1.48 const Uint32 Tracer::LEVEL0 = 0;
|
64 mike 1.2 const Uint32 Tracer::LEVEL1 = (1 << 0);
65 const Uint32 Tracer::LEVEL2 = (1 << 1);
66 const Uint32 Tracer::LEVEL3 = (1 << 2);
67 const Uint32 Tracer::LEVEL4 = (1 << 3);
|
68 marek 1.48 const Uint32 Tracer::LEVEL5 = (1 << 4);
|
69 mike 1.2
70 // Set the Enter and Exit messages
|
71 kumpf 1.13 const char Tracer::_METHOD_ENTER_MSG[] = "Entering method";
72 const char Tracer::_METHOD_EXIT_MSG[] = "Exiting method";
|
73 mike 1.2
74 // Initialize singleton instance of Tracer
75 Tracer* Tracer::_tracerInstance = 0;
|
76 chip 1.20
|
77 mike 1.2 // Set component separator
78 const char Tracer::_COMPONENT_SEPARATOR = ',';
79
80 // Set the number of defined components
|
81 chip 1.20 const Uint32 Tracer::_NUM_COMPONENTS =
|
82 mike 1.2 sizeof(TRACE_COMPONENT_LIST)/sizeof(TRACE_COMPONENT_LIST[0]);
83
84 // Set the line maximum
85 const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21;
86
|
87 kumpf 1.3 // Set the max PID and Thread ID Length
|
88 mike 1.39 const Uint32 Tracer::_STRLEN_MAX_PID_TID = 21;
|
89 kumpf 1.3
|
90 r.kieninger 1.30 // Initialize public indicator of trace state
|
91 david.dillard 1.32 Boolean Tracer::_traceOn = false;
|
92 r.kieninger 1.30
|
93 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
94 // Tracer constructor
95 // Constructor is private to preclude construction of Tracer objects
96 // Single Instance of Tracer is maintained for each process.
97 ////////////////////////////////////////////////////////////////////////////////
98 Tracer::Tracer()
|
99 aruran.ms 1.33 : _traceComponentMask(new Boolean[_NUM_COMPONENTS]),
|
100 r.kieninger 1.49 _traceFacility(TRACE_FACILITY_FILE),
|
101 aruran.ms 1.33 _traceLevelMask(0),
|
102 r.kieninger 1.49 _traceHandler(0)
|
103 mike 1.2 {
|
104 r.kieninger 1.49 // Instantiate trace handler according to configured facility
105 _traceHandler.reset( getTraceHandler(_traceFacility) );
106
|
107 mike 1.2 // Initialize ComponentMask array to false
|
108 chip 1.20 for (Uint32 index=0;index < _NUM_COMPONENTS;
|
109 david.dillard 1.32 (_traceComponentMask.get())[index++]=false);
|
110 r.kieninger 1.49
|
111 marek 1.48 // NO componets are set
112 _componentsAreSet=false;
|
113 mike 1.2 }
|
114 chip 1.20
|
115 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
116 //Tracer destructor
117 ////////////////////////////////////////////////////////////////////////////////
118 Tracer::~Tracer()
119 {
120 delete _tracerInstance;
121 }
122
123
124 ////////////////////////////////////////////////////////////////////////////////
|
125 r.kieninger 1.49 //Factory function for the trace handler instances.
126 ////////////////////////////////////////////////////////////////////////////////
127 TraceHandler* Tracer::getTraceHandler( Uint32 traceFacility )
128 {
129 TraceHandler * trcHandler;
130 switch(traceFacility)
131 {
132 case TRACE_FACILITY_LOG:
133 trcHandler = new TraceLogHandler();
134 break;
135
136 case TRACE_FACILITY_FILE:
137 default:
138 trcHandler = new TraceFileHandler();
139 }
140
141 return trcHandler;
142 }
143
144 ////////////////////////////////////////////////////////////////////////////////
|
145 mike 1.2 //Traces the given message - Overloaded for including FileName and Line number
146 ////////////////////////////////////////////////////////////////////////////////
147 void Tracer::_trace(
148 const char* fileName,
149 const Uint32 lineNum,
150 const Uint32 traceComponent,
151 const char* fmt,
152 va_list argList)
153 {
154 char* message;
|
155 marek 1.42 //
156 // Allocate memory for the message string
157 // Needs to be updated if additional info is added
158 //
159 message = new char[strlen(fileName) +
160 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8];
161 sprintf(
162 message,
163 "[%d:%s:%s:%u]: ",
164 System::getPID(),
165 Threads::id().buffer,
166 fileName,
167 lineNum);
|
168 mike 1.2
|
169 marek 1.42 _trace(traceComponent, message, fmt, argList);
170 delete [] message;
|
171 mike 1.2 }
172
173 ////////////////////////////////////////////////////////////////////////////////
|
174 kumpf 1.5 //Traces the message in the given CIMException object.
175 ////////////////////////////////////////////////////////////////////////////////
176 void Tracer::_traceCIMException(
177 const Uint32 traceComponent,
|
178 kumpf 1.40 const CIMException& cimException)
|
179 marek 1.42 {
|
180 kumpf 1.43 // get the CIMException trace message string
181 CString traceMsg =
182 TraceableCIMException(cimException).getTraceDescription().getCString();
183 // trace the string
184 _traceCString(traceComponent, "", (const char*) traceMsg);
|
185 mike 1.2 }
186
|
187 sushma.fernandes 1.45 SharedArrayPtr<char> Tracer::getHTTPRequestMessage(
188 const Buffer& requestMessage)
189 {
190 const Uint32 requestSize = requestMessage.size();
191
192 // Make a copy of the request message.
193 SharedArrayPtr<char>
194 requestBuf(new char [requestSize + 1]);
195 strncpy(requestBuf.get(), requestMessage.getData(), requestSize);
196 requestBuf.get()[requestSize] = 0;
197
198 //
199 // Check if requestBuffer contains a Basic authorization header.
200 // If true, suppress the user/passwd info in the request buffer.
201 //
202 char* sep;
203 const char* line = requestBuf.get();
204
205 while ((sep = HTTPMessage::findSeparator(
206 line, (Uint32)(requestSize - (line - requestBuf.get())))) &&
207 (line != sep))
208 sushma.fernandes 1.45 {
209 if (HTTPMessage::expectHeaderToken(line, "Authorization") &&
210 HTTPMessage::expectHeaderToken(line, ":") &&
211 HTTPMessage::expectHeaderToken(line, "Basic"))
212 {
213 // Suppress the user/passwd info
214 HTTPMessage::skipHeaderWhitespace(line);
215 for ( char* userpass = (char*)line ;
216 userpass < sep;
217 *userpass = 'X', userpass++);
218
219 break;
220 }
221
222 line = sep + ((*sep == '\r') ? 2 : 1);
223 }
224
225 return requestBuf;
226 }
227
|
228 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
229 marek 1.42 //Traces method entry and exit
|
230 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
231 marek 1.42 void Tracer::_traceMethod(
|
232 mike 1.2 const char* fileName,
233 const Uint32 lineNum,
234 const Uint32 traceComponent,
|
235 marek 1.42 const char* methodEntryExit,
236 const char* method)
|
237 mike 1.2 {
238 char* message;
239
|
240 marek 1.42 //
241 // Allocate memory for the message string
242 // Needs to be updated if additional info is added
243 //
244 // assume Method entry/exit string 15 characters long
245 // +1 space character
246 message = new char[ strlen(fileName) +
247 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8
248 + 16];
249
250 sprintf(
251 message,
252 "[%d:%s:%s:%u]: %s ",
253 System::getPID(),
254 Threads::id().buffer,
255 fileName,
256 lineNum,
257 methodEntryExit);
258
259 _traceCString(traceComponent, message, method);
|
260 carson.hovey 1.37
|
261 marek 1.42 delete [] message;
|
262 mike 1.2 }
263
264
265 ////////////////////////////////////////////////////////////////////////////////
266 //Checks if trace is enabled for the given component and level
267 ////////////////////////////////////////////////////////////////////////////////
|
268 marek 1.46 Boolean Tracer::isTraceEnabled(
|
269 kumpf 1.40 const Uint32 traceComponent,
|
270 mike 1.2 const Uint32 traceLevel)
271 {
272 Tracer* instance = _getInstance();
273 if (traceComponent >= _NUM_COMPONENTS)
274 {
|
275 david.dillard 1.32 return false;
|
276 mike 1.2 }
|
277 a.arora 1.22 return (((instance->_traceComponentMask.get())[traceComponent]) &&
|
278 kumpf 1.40 (traceLevel & instance->_traceLevelMask));
|
279 mike 1.2 }
280
281 ////////////////////////////////////////////////////////////////////////////////
|
282 marek 1.42 //Called by all trace interfaces with variable arguments
283 //to log message to trace file
|
284 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
285 void Tracer::_trace(
286 const Uint32 traceComponent,
287 const char* message,
288 const char* fmt,
289 va_list argList)
290 {
291 char* msgHeader;
292
293 // Get the current system time and prepend to message
294 String currentTime = System::getCurrentASCIITime();
|
295 kumpf 1.17 CString timeStamp = currentTime.getCString();
|
296 mike 1.2
|
297 kumpf 1.3 //
|
298 chip 1.20 // Allocate messageHeader.
|
299 kumpf 1.3 // Needs to be updated if additional info is added
300 //
|
301 mday 1.19
|
302 mike 1.2 // Construct the message header
|
303 chip 1.20 // The message header is in the following format
|
304 mike 1.2 // timestamp: <component name> [file name:line number]
|
305 joyce.j 1.26 if (*message != '\0')
|
306 mike 1.2 {
|
307 kumpf 1.40 // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used
308 // in this format string
309 msgHeader = new char [strlen(message) +
310 strlen(TRACE_COMPONENT_LIST[traceComponent]) +
311 strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];
312
313 sprintf(msgHeader, "%s: %s %s", (const char*)timeStamp,
314 TRACE_COMPONENT_LIST[traceComponent], message);
|
315 mike 1.2 }
316 else
317 {
|
318 kumpf 1.3 //
|
319 marek 1.42 // Since the message is blank, form a string using the pid and tid
|
320 kumpf 1.3 //
|
321 kumpf 1.40 char* tmpBuffer;
|
322 kumpf 1.3
323 //
|
324 chip 1.20 // Allocate messageHeader.
|
325 kumpf 1.3 // Needs to be updated if additional info is added
326 //
|
327 mike 1.39 tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6];
|
328 kumpf 1.40 sprintf(tmpBuffer, "[%u:%s]: ",
329 System::getPID(), Threads::id().buffer);
330 msgHeader = new char[strlen(timeStamp) +
331 strlen(TRACE_COMPONENT_LIST[traceComponent]) +
332 strlen(tmpBuffer) + 1 + 5];
333
334 sprintf(msgHeader, "%s: %s %s ", (const char*)timeStamp,
335 TRACE_COMPONENT_LIST[traceComponent], tmpBuffer);
336 delete [] tmpBuffer;
|
337 mike 1.2 }
338
339 // Call trace file handler to write message
340 _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);
|
341 chip 1.20
342 delete [] msgHeader;
|
343 mike 1.2 }
344
345 ////////////////////////////////////////////////////////////////////////////////
|
346 marek 1.42 //Called by all trace interfaces using a character string without format string
347 //to log message to trace file
348 ////////////////////////////////////////////////////////////////////////////////
349 void Tracer::_traceCString(
350 const Uint32 traceComponent,
351 const char* message,
352 const char* cstring)
353 {
354 char* completeMessage;
355
356 // Get the current system time and prepend to message
357 String currentTime = System::getCurrentASCIITime();
358 CString timeStamp = currentTime.getCString();
359 //
360 // Allocate completeMessage.
361 // Needs to be updated if additional info is added
362 //
363
364 // Construct the message header
365 // The message header is in the following format
366 // timestamp: <component name> [file name:line number]
367 marek 1.42 if (*message != '\0')
368 {
369 // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used
370 // in this format string
371 completeMessage = new char [strlen(message) +
372 strlen(TRACE_COMPONENT_LIST[traceComponent]) +
373 strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5 +
374 strlen(cstring) ];
375
376 sprintf(completeMessage, "%s: %s %s%s", (const char*)timeStamp,
377 TRACE_COMPONENT_LIST[traceComponent], message, cstring);
378 }
379 else
380 {
381 //
382 // Since the message is blank, form a string using the pid and tid
383 //
384 char* tmpBuffer;
385
386 //
387 // Allocate messageHeader.
388 marek 1.42 // Needs to be updated if additional info is added
389 //
390 tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6];
391 sprintf(tmpBuffer, "[%u:%s]: ",
392 System::getPID(), Threads::id().buffer);
393
394 completeMessage = new char[strlen(timeStamp) +
395 strlen(TRACE_COMPONENT_LIST[traceComponent]) +
396 strlen(tmpBuffer) + 1 + 5 +
397 strlen(cstring)];
398
399 sprintf(completeMessage, "%s: %s %s %s", (const char*)timeStamp,
400 TRACE_COMPONENT_LIST[traceComponent], tmpBuffer, cstring);
401 delete [] tmpBuffer;
402 }
403
404 // Call trace file handler to write message
405 _getInstance()->_traceHandler->handleMessage(completeMessage);
406
407 delete [] completeMessage;
408 }
409 marek 1.42
410
411 ////////////////////////////////////////////////////////////////////////////////
|
412 mike 1.2 //Validate the trace file
413 ////////////////////////////////////////////////////////////////////////////////
|
414 kumpf 1.10 Boolean Tracer::isValidFileName(const char* filePath)
|
415 mike 1.2 {
|
416 kumpf 1.23 String moduleName = _getInstance()->_moduleName;
417 if (moduleName == String::EMPTY)
418 {
|
419 r.kieninger 1.49 return
420 _getInstance()->_traceHandler->isValidMessageDestination(filePath);
|
421 kumpf 1.23 }
422 else
423 {
424 String extendedFilePath = String(filePath) + "." + moduleName;
|
425 r.kieninger 1.49 return _getInstance()->_traceHandler->isValidMessageDestination(
|
426 kumpf 1.40 extendedFilePath.getCString());
|
427 kumpf 1.23 }
|
428 mike 1.2 }
429
430 ////////////////////////////////////////////////////////////////////////////////
431 //Validate the trace components
432 ////////////////////////////////////////////////////////////////////////////////
|
433 kumpf 1.23 Boolean Tracer::isValidComponents(const String& traceComponents)
|
434 kumpf 1.10 {
435 String invalidComponents;
436 return isValidComponents(traceComponents, invalidComponents);
437 }
438
439 Boolean Tracer::isValidComponents(
|
440 kumpf 1.40 const String& traceComponents,
441 String& invalidComponents)
|
442 mike 1.2 {
443 // Validate the trace components and modify the traceComponents argument
444 // to reflect the invalid components
445
446 Uint32 position=0;
447 Uint32 index=0;
|
448 kumpf 1.44 String componentName;
449 String componentStr;
|
450 mike 1.2 Boolean validComponent=false;
451 Boolean retCode=true;
452
453 componentStr = traceComponents;
454 invalidComponents = String::EMPTY;
455
456 if (componentStr != String::EMPTY)
457 {
458 // Check if ALL is specified
459 if (String::equalNoCase(componentStr,"ALL"))
460 {
|
461 marek 1.48 return true;
|
462 mike 1.2 }
463
464 // Append _COMPONENT_SEPARATOR to the end of the traceComponents
|
465 kumpf 1.16 componentStr.append(_COMPONENT_SEPARATOR);
|
466 mike 1.2
467 while (componentStr != String::EMPTY)
468 {
|
469 david.dillard 1.32 //
|
470 mike 1.2 // Get the Component name from traceComponents.
471 // Components are separated by _COMPONENT_SEPARATOR
|
472 david.dillard 1.32 //
|
473 mike 1.2 position = componentStr.find(_COMPONENT_SEPARATOR);
474 componentName = componentStr.subString(0,(position));
475
476 // Lookup the index for Component name in TRACE_COMPONENT_LIST
477 index = 0;
478 validComponent = false;
479
480 while (index < _NUM_COMPONENTS)
481 {
|
482 chip 1.20 if (String::equalNoCase(
|
483 david.dillard 1.32 componentName, TRACE_COMPONENT_LIST[index]))
|
484 mike 1.2 {
485 // Found component, break from the loop
|
486 david.dillard 1.32 validComponent = true;
|
487 mike 1.2 break;
488 }
489 else
490 {
491 index++;
492 }
493 }
494
495 // Remove the searched componentname from the traceComponents
496 componentStr.remove(0,position+1);
497
|
498 kumpf 1.40 if (!validComponent)
|
499 david.dillard 1.32 {
500 invalidComponents.append(componentName);
501 invalidComponents.append(_COMPONENT_SEPARATOR);
|
502 mike 1.2 }
503 }
504 }
505 else
506 {
|
507 david.dillard 1.32 // trace components is empty, it is a valid value so return true
|
508 marek 1.48 return true;
|
509 mike 1.2 }
|
510 kumpf 1.40
511 if (invalidComponents != String::EMPTY)
|
512 mike 1.2 {
|
513 david.dillard 1.32 retCode = false;
514 //
515 // Remove the extra ',' at the end
516 //
517 invalidComponents.remove(
518 invalidComponents.reverseFind(_COMPONENT_SEPARATOR));
|
519 mike 1.2 }
520 return retCode;
521 }
|
522 chip 1.20
|
523 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
524 r.kieninger 1.49 //Validate the trace facility
525 ////////////////////////////////////////////////////////////////////////////////
526 Boolean Tracer::isValidTraceFacility(const String& traceFacility)
527 {
528 Boolean retCode = false;
529
530 if (traceFacility.size() != 0)
531 {
532 Uint32 index = 0;
533 while (TRACE_FACILITY_LIST[index] != 0 )
534 {
535 if (String::equalNoCase( traceFacility,TRACE_FACILITY_LIST[index]))
536 {
537 retCode = true;
538 break;
539 }
540 index++;
541 }
542 }
543
544 return retCode;
545 r.kieninger 1.49 }
546
547 ////////////////////////////////////////////////////////////////////////////////
|
548 kumpf 1.23 //Set the name of the module being traced
549 ////////////////////////////////////////////////////////////////////////////////
550 void Tracer::setModuleName(const String& moduleName)
551 {
552 _getInstance()->_moduleName = moduleName;
553 }
554
555 ////////////////////////////////////////////////////////////////////////////////
|
556 mike 1.2 //Returns the Singleton instance of the Tracer
557 ////////////////////////////////////////////////////////////////////////////////
558 Tracer* Tracer::_getInstance()
559 {
560 if (_tracerInstance == 0)
561 {
562 _tracerInstance = new Tracer();
563 }
564 return _tracerInstance;
565 }
566
|
567 chip 1.20 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
|
568 karl 1.35 // interfaces. This section defines the trace functions IF the remove
569 // trace flag is NOT set. If it is set, they are defined as empty functions
570 // in the header file.
|
571 mike 1.2
572 #ifndef PEGASUS_REMOVE_TRACE
573
574 ////////////////////////////////////////////////////////////////////////////////
575 //Set the trace file
576 ////////////////////////////////////////////////////////////////////////////////
577 Uint32 Tracer::setTraceFile(const char* traceFile)
578 {
|
579 kumpf 1.25 if (*traceFile == 0)
580 {
581 return 1;
582 }
583
|
584 kumpf 1.23 String moduleName = _getInstance()->_moduleName;
585 if (moduleName == String::EMPTY)
586 {
|
587 r.kieninger 1.49 return _getInstance()->_traceHandler->setMessageDestination(traceFile);
|
588 kumpf 1.23 }
589 else
590 {
591 String extendedTraceFile = String(traceFile) + "." + moduleName;
|
592 r.kieninger 1.49 return _getInstance()->_traceHandler->setMessageDestination(
|
593 kumpf 1.40 extendedTraceFile.getCString());
|
594 kumpf 1.23 }
|
595 chip 1.20 }
|
596 mike 1.2
597 ////////////////////////////////////////////////////////////////////////////////
598 //Set the trace level
599 ////////////////////////////////////////////////////////////////////////////////
600 Uint32 Tracer::setTraceLevel(const Uint32 traceLevel)
601 {
602 Uint32 retCode = 0;
603
604 switch (traceLevel)
605 {
|
606 marek 1.48 case LEVEL0:
607 _getInstance()->_traceLevelMask = 0x00;
608 break;
609
|
610 david.dillard 1.32 case LEVEL1:
|
611 mike 1.2 _getInstance()->_traceLevelMask = 0x01;
|
612 david.dillard 1.32 break;
|
613 chip 1.20
|
614 mike 1.2 case LEVEL2:
615 _getInstance()->_traceLevelMask = 0x03;
|
616 david.dillard 1.32 break;
|
617 mike 1.2
618 case LEVEL3:
619 _getInstance()->_traceLevelMask = 0x07;
|
620 david.dillard 1.32 break;
|
621 mike 1.2
622 case LEVEL4:
623 _getInstance()->_traceLevelMask = 0x0F;
|
624 david.dillard 1.32 break;
|
625 mike 1.2
|
626 marek 1.48 case LEVEL5:
627 _getInstance()->_traceLevelMask = 0x1F;
628 break;
629
|
630 mike 1.2 default:
|
631 marek 1.48 _getInstance()->_traceLevelMask = 0x00;
|
632 mike 1.2 retCode = 1;
633 }
|
634 marek 1.48
635 if (_getInstance()->_componentsAreSet &&
636 _getInstance()->_traceLevelMask )
637 {
638 _traceOn = true;
639 }
640 else
641 {
642 _traceOn = false;
643 }
644
|
645 mike 1.2 return retCode;
646 }
647
648 ////////////////////////////////////////////////////////////////////////////////
|
649 chip 1.20 // Set components to be traced.
|
650 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
651 kumpf 1.23 void Tracer::setTraceComponents(const String& traceComponents)
|
652 mike 1.2 {
|
653 marek 1.48 Tracer* instance = _getInstance();
|
654 chip 1.20
|
655 marek 1.48 // Check if ALL is specified
656 if (String::equalNoCase(traceComponents,"ALL"))
|
657 mike 1.2 {
|
658 marek 1.48 for (Uint32 index = 0; index < _NUM_COMPONENTS; index++)
|
659 mike 1.2 {
|
660 marek 1.48 (instance->_traceComponentMask.get())[index] = true;
|
661 mike 1.2 }
662
|
663 marek 1.48 instance->_componentsAreSet=true;
664
665 // If tracing isn't turned off by a traceLevel of zero, let's
666 // turn on the flag that activates tracing.
667 _traceOn = (instance->_traceLevelMask != LEVEL0);
668
669 return;
670 }
671
672 // initialize ComponentMask array to False
673 for (Uint32 index = 0; index < _NUM_COMPONENTS; index++)
674 {
675 (instance->_traceComponentMask.get())[index] = false;
676 }
677 _traceOn = false;
678 instance->_componentsAreSet=false;
679
680 if (traceComponents != String::EMPTY)
681 {
682 Uint32 index = 0;
683 Uint32 position = 0;
684 marek 1.48 String componentName;
685 String componentStr = traceComponents;
|
686 mike 1.2
|
687 marek 1.48
|
688 r.kieninger 1.30 // Append _COMPONENT_SEPARATOR to the end of the traceComponents
|
689 kumpf 1.16 componentStr.append(_COMPONENT_SEPARATOR);
|
690 mike 1.2
691 while (componentStr != String::EMPTY)
692 {
|
693 chip 1.20 // Get the Component name from traceComponents.
|
694 r.kieninger 1.30 // Components are separated by _COMPONENT_SEPARATOR
|
695 mike 1.2 position = componentStr.find(_COMPONENT_SEPARATOR);
|
696 r.kieninger 1.30 componentName = componentStr.subString(0,(position));
|
697 mike 1.2
|
698 r.kieninger 1.30 // Lookup the index for Component name in TRACE_COMPONENT_LIST
|
699 mike 1.2 index = 0;
|
700 r.kieninger 1.30 while (index < _NUM_COMPONENTS)
701 {
702 if (String::equalNoCase(
703 componentName,TRACE_COMPONENT_LIST[index]))
704 {
|
705 marek 1.48 (instance->_traceComponentMask.get())[index] = true;
706
707 instance->_componentsAreSet=true;
|
708 mike 1.2
709 // Found component, break from the loop
710 break;
|
711 r.kieninger 1.30 }
712 else
713 {
714 index++;
|
715 mike 1.2 }
|
716 chip 1.20 }
|
717 mike 1.2
718 // Remove the searched componentname from the traceComponents
719 componentStr.remove(0,position+1);
720 }
|
721 marek 1.48
722 // If one of the components was set for tracing and the traceLevel
723 // is not zero, then turn on tracing.
724 _traceOn = (instance->_componentsAreSet &&
725 (instance->_traceLevelMask != LEVEL0));
|
726 mike 1.2 }
|
727 marek 1.48
|
728 mike 1.2 return ;
729 }
730
|
731 r.kieninger 1.49 ////////////////////////////////////////////////////////////////////////////////
732 // Set the trace facility to be used
733 ////////////////////////////////////////////////////////////////////////////////
734 Uint32 Tracer::setTraceFacility(const String& traceFacility)
735 {
736 Uint32 retCode = 0;
737 Tracer* instance = _getInstance();
738
739 if (traceFacility.size() != 0)
740 {
741 Uint32 index = 0;
742 while (TRACE_FACILITY_LIST[index] != 0 )
743 {
744 if (String::equalNoCase( traceFacility,TRACE_FACILITY_LIST[index]))
745 {
746 if (index != instance->_traceFacility)
747 {
748 instance->_traceFacility = index;
749 instance->_traceHandler.reset(
750 instance->getTraceHandler(instance->_traceFacility));
751 }
752 r.kieninger 1.49 retCode = 1;
753 break;
754 }
755 index++;
756 }
757 }
758
759 return retCode;
760 }
761
|
762 marek 1.50 ////////////////////////////////////////////////////////////////////////////////
763 // Get the trace facility in use
764 ////////////////////////////////////////////////////////////////////////////////
765 Uint32 Tracer::getTraceFacility()
766 {
767 return _getInstance()->_traceFacility;
768 }
|
769 r.kieninger 1.49
|
770 kumpf 1.40 void Tracer::traceEnter(
771 TracerToken& token,
|
772 karl 1.35 const char* file,
773 size_t line,
|
774 kumpf 1.40 Uint32 traceComponent,
|
775 karl 1.35 const char* method)
776 {
|
777 marek 1.42 token.component = traceComponent;
778 token.method = method;
779
|
780 marek 1.48 if (isTraceEnabled(traceComponent, LEVEL5))
|
781 karl 1.35 {
|
782 marek 1.42 _traceMethod(
783 file, (Uint32)line, traceComponent,
|
784 a.dunfey 1.41 _METHOD_ENTER_MSG, method);
|
785 karl 1.35 }
786 }
787
788 void Tracer::traceExit(
789 TracerToken& token,
790 const char* file,
791 size_t line)
792 {
|
793 marek 1.48 if (isTraceEnabled(token.component, LEVEL5) && token.method)
|
794 marek 1.42 _traceMethod(
795 file, (Uint32)line, token.component,
|
796 kumpf 1.40 _METHOD_EXIT_MSG, token.method);
|
797 karl 1.35 }
798
|
799 marek 1.46 ////////////////////////////////////////////////////////////////////////////////
800 //Traces the given string - Overloaded to include the fileName and line number
801 //of trace origin.
802 ////////////////////////////////////////////////////////////////////////////////
803 void Tracer::traceCString(
|
804 karl 1.35 const char* fileName,
805 const Uint32 lineNum,
806 const Uint32 traceComponent,
|
807 marek 1.46 const char* cstring)
|
808 karl 1.35 {
|
809 marek 1.46 char* message;
|
810 karl 1.35
|
811 marek 1.46 //
812 // Allocate memory for the message string
813 // Needs to be updated if additional info is added
814 //
815 message = new char[strlen(fileName) +
816 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8];
817 sprintf(
|
818 r.kieninger 1.49 message,
819 "[%d:%s:%s:%u]: ",
820 System::getPID(),
821 Threads::id().buffer,
822 fileName,
823 lineNum);
|
824 karl 1.35
|
825 marek 1.46 _traceCString(traceComponent, message, cstring);
826 delete [] message;
|
827 karl 1.35 }
828
|
829 marek 1.42 void Tracer::traceCIMException(
|
830 kumpf 1.40 const Uint32 traceComponent,
|
831 marek 1.42 const Uint32 traceLevel,
832 const CIMException& cimException)
|
833 karl 1.35 {
|
834 marek 1.46 if (isTraceEnabled(traceComponent, traceLevel))
|
835 marek 1.42 {
836 _traceCIMException(traceComponent, cimException);
837 }
|
838 karl 1.35 }
839
840 #endif /* !PEGASUS_REMOVE_TRACE */
|
841 mike 1.2
842 PEGASUS_NAMESPACE_END
|