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

Diff for /pegasus/src/Pegasus/Common/Tracer.cpp between version 1.38 and 1.50

version 1.38, 2006/08/21 15:31:03 version 1.50, 2008/05/27 17:35:41
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)  
 //  
 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)  
 //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 //              Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2498  
 //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)  
 //              David Dillard, Symantec Corp. (david_dillard@symantec.com)  
 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 4547  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
   #include <Pegasus/Common/TraceFileHandler.h>
   #include <Pegasus/Common/TraceLogHandler.h>
 #include <Pegasus/Common/Thread.h> #include <Pegasus/Common/Thread.h>
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
   #include <Pegasus/Common/HTTPMessage.h>
   
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   
   // Defines the value values for trace facilities
   // Keep the TRACE_FACILITY_LIST in sync with the TRACE_FACILITY_INDEX,
   // so that the index matches the according string in the list.
   char const* Tracer::TRACE_FACILITY_LIST[] =
   {
       "File",
       "Log",
       0
   };
   
   
 // Set the trace levels // Set the trace levels
 // These levels will be compared against a trace level mask to determine // These levels will be compared against a trace level mask to determine
 // if a specific trace level is enabled // if a specific trace level is enabled
  
   const Uint32 Tracer::LEVEL0 =  0;
 const Uint32 Tracer::LEVEL1 = (1 << 0); const Uint32 Tracer::LEVEL1 = (1 << 0);
 const Uint32 Tracer::LEVEL2 = (1 << 1); const Uint32 Tracer::LEVEL2 = (1 << 1);
 const Uint32 Tracer::LEVEL3 = (1 << 2); const Uint32 Tracer::LEVEL3 = (1 << 2);
 const Uint32 Tracer::LEVEL4 = (1 << 3); const Uint32 Tracer::LEVEL4 = (1 << 3);
   const Uint32 Tracer::LEVEL5 = (1 << 4);
 // Set the return codes  
 const Boolean Tracer::_SUCCESS = 1;  
 const Boolean Tracer::_FAILURE = 0;  
  
 // Set the Enter and Exit messages // Set the Enter and Exit messages
 const char Tracer::_METHOD_ENTER_MSG[] = "Entering method"; const char Tracer::_METHOD_ENTER_MSG[] = "Entering method";
 const char Tracer::_METHOD_EXIT_MSG[]  = "Exiting method"; const char Tracer::_METHOD_EXIT_MSG[]  = "Exiting method";
  
 // Set Log messages  
 const char Tracer::_LOG_MSG[] = "LEVEL1 may only be used with trace macros PEG_METHOD_ENTER/PEG_METHOD_EXIT.";  
   
 // Initialize singleton instance of Tracer // Initialize singleton instance of Tracer
 Tracer* Tracer::_tracerInstance = 0; Tracer* Tracer::_tracerInstance = 0;
  
Line 84 
Line 85 
 const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21; const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21;
  
 // Set the max PID and Thread ID Length // Set the max PID and Thread ID Length
 const Uint32 Tracer::_STRLEN_MAX_PID_TID = 20;  const Uint32 Tracer::_STRLEN_MAX_PID_TID = 21;
  
 // Initialize public indicator of trace state // Initialize public indicator of trace state
 Boolean Tracer::_traceOn = false; Boolean Tracer::_traceOn = false;
Line 96 
Line 97 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer::Tracer() Tracer::Tracer()
     : _traceComponentMask(new Boolean[_NUM_COMPONENTS]),     : _traceComponentMask(new Boolean[_NUM_COMPONENTS]),
         _traceFacility(TRACE_FACILITY_FILE),
       _traceLevelMask(0),       _traceLevelMask(0),
       _traceHandler(new TraceFileHandler())        _traceHandler(0)
 { {
       // Instantiate trace handler according to configured facility
       _traceHandler.reset( getTraceHandler(_traceFacility) );
   
     // Initialize ComponentMask array to false     // Initialize ComponentMask array to false
     for (Uint32 index=0;index < _NUM_COMPONENTS;     for (Uint32 index=0;index < _NUM_COMPONENTS;
         (_traceComponentMask.get())[index++]=false);         (_traceComponentMask.get())[index++]=false);
   
       // NO componets are set
       _componentsAreSet=false;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 114 
Line 122 
  
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces the given message  //Factory function for the trace handler instances.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_trace(  TraceHandler* Tracer::getTraceHandler( Uint32 traceFacility )
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char* fmt,  
     va_list argList)  
 {  
     if ( traceLevel == LEVEL1 )  
     {     {
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );      TraceHandler * trcHandler;
     }      switch(traceFacility)
     else  
     {  
         if (_isTraceEnabled(traceComponent,traceLevel))  
         {         {
             _trace(traceComponent,"",fmt,argList);          case TRACE_FACILITY_LOG:
         }              trcHandler = new TraceLogHandler();
               break;
   
           case TRACE_FACILITY_FILE:
           default:
               trcHandler = new TraceFileHandler();
     }     }
   
       return trcHandler;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 142 
Line 148 
     const char* fileName,     const char* fileName,
     const Uint32 lineNum,     const Uint32 lineNum,
     const Uint32 traceComponent,     const Uint32 traceComponent,
     const Uint32 traceLevel,  
     const char* fmt,     const char* fmt,
     va_list argList)     va_list argList)
 { {
     char* message;     char* message;
   
     if ( traceLevel == LEVEL1 )  
     {  
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );  
     }  
     else  
     {  
         if (_isTraceEnabled(traceComponent,traceLevel))  
         {  
             //             //
             // Allocate memory for the message string             // Allocate memory for the message string
             // Needs to be updated if additional info is added             // Needs to be updated if additional info is added
Line 173 
Line 169 
             _trace(traceComponent,message,fmt,argList);             _trace(traceComponent,message,fmt,argList);
             delete []message;             delete []message;
         }         }
     }  
 }  
   
 ////////////////////////////////////////////////////////////////////////////////  
 //Traces the given buffer  
 ////////////////////////////////////////////////////////////////////////////////  
 void Tracer::_traceBuffer(  
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char*  data,  
     const Uint32 size)  
 {  
     if ( traceLevel == LEVEL1 )  
     {  
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );  
     }  
     else  
     {  
         if (_isTraceEnabled(traceComponent,traceLevel))  
         {  
             char* tmpBuf = new char[size+1];  
   
             strncpy( tmpBuf, data, size );  
             tmpBuf[size] = '\0';  
             trace(traceComponent,traceLevel,"%s",tmpBuf);  
   
             delete []tmpBuf;  
         }  
     }  
 }  
 ////////////////////////////////////////////////////////////////////////////////  
 //Traces the given buffer - Overloaded for including FileName and Line number  
 ////////////////////////////////////////////////////////////////////////////////  
 void Tracer::_traceBuffer(  
     const char* fileName,  
     const Uint32 lineNum,  
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char*  data,  
     const Uint32 size)  
 {  
     if ( traceLevel == LEVEL1 )  
     {  
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );  
     }  
     else  
     {  
         if ( _isTraceEnabled( traceComponent, traceLevel ) )  
         {  
             char* tmpBuf = new char[size+1];  
   
             strncpy( tmpBuf, data, size );  
             tmpBuf[size] = '\0';  
             trace(fileName,lineNum,traceComponent,traceLevel,"%s",tmpBuf);  
   
             delete []tmpBuf;  
         }  
     }  
 }  
   
 ////////////////////////////////////////////////////////////////////////////////  
 //Traces the given string  
 ////////////////////////////////////////////////////////////////////////////////  
 void Tracer::_traceString(  
     const Uint32   traceComponent,  
     const Uint32   traceLevel,  
     const String&  traceString)  
 {  
     if ( traceLevel == LEVEL1 )  
     {  
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );  
     }  
     else  
     {  
         if (_isTraceEnabled(traceComponent,traceLevel))  
         {  
             trace(traceComponent,traceLevel,"%s",  
                        (const char *)traceString.getCString());  
         }  
     }  
 }  
   
 ////////////////////////////////////////////////////////////////////////////////  
 //Traces the given string - Overloaded to include the fileName and line number  
 //of trace origin.  
 ////////////////////////////////////////////////////////////////////////////////  
 void Tracer::_traceString(  
     const char*   fileName,  
     const Uint32  lineNum,  
     const Uint32  traceComponent,  
     const Uint32  traceLevel,  
     const String& traceString)  
 {  
     if ( traceLevel == LEVEL1 )  
     {  
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );  
     }  
     else  
     {  
         if ( _isTraceEnabled( traceComponent, traceLevel ) )  
         {  
             trace(fileName,lineNum,traceComponent,traceLevel,"%s",  
                      (const char *)traceString.getCString());  
         }  
     }  
 }  
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces the message in the given CIMException object. //Traces the message in the given CIMException object.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_traceCIMException( void Tracer::_traceCIMException(
     const Uint32 traceComponent,     const Uint32 traceComponent,
     const Uint32 traceLevel,      const CIMException& cimException)
     CIMException cimException)  
 {  
     if ( traceLevel == LEVEL1 )  
     {  
         trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );  
     }  
     else  
     {  
         if ( _isTraceEnabled( traceComponent, traceLevel ) )  
         {         {
             // get the CIMException trace message string             // get the CIMException trace message string
             String traceMsg =      CString traceMsg =
                 TraceableCIMException(cimException).getTraceDescription();          TraceableCIMException(cimException).getTraceDescription().getCString();
   
             // trace the string             // trace the string
             _traceString(traceComponent, traceLevel, traceMsg);      _traceCString(traceComponent, "", (const char*) traceMsg);
         }  
     }  
 } }
  
 ////////////////////////////////////////////////////////////////////////////////  SharedArrayPtr<char> Tracer::getHTTPRequestMessage(
 //Traces method entry      const Buffer& requestMessage)
 ////////////////////////////////////////////////////////////////////////////////  
 void Tracer::_traceEnter(  
     const char* fileName,  
     const Uint32 lineNum,  
     const Uint32 traceComponent,  
     const char* fmt,  
     ...)  
 { {
     va_list argList;      const Uint32 requestSize = requestMessage.size();
     char* message;  
  
     if (_isTraceEnabled(traceComponent,LEVEL1))      // Make a copy of the request message.
     {      SharedArrayPtr<char>
           requestBuf(new char [requestSize + 1]);
         va_start(argList,fmt);      strncpy(requestBuf.get(), requestMessage.getData(), requestSize);
       requestBuf.get()[requestSize] = 0;
  
         //         //
         // Allocate memory for the message string      // Check if requestBuffer contains a Basic authorization header.
         // Needs to be updated if additional info is added      // If true, suppress the user/passwd info in the request buffer.
         //         //
         message = new char[ strlen(fileName) +      char* sep;
                             _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];      const char* line = requestBuf.get();
  
         sprintf(      while ((sep = HTTPMessage::findSeparator(
            message,          line, (Uint32)(requestSize - (line - requestBuf.get())))) &&
            "[%d:%s:%s:%u]: ",          (line != sep))
            System::getPID(),      {
            Threads::id().buffer,          if (HTTPMessage::expectHeaderToken(line, "Authorization") &&
            fileName,               HTTPMessage::expectHeaderToken(line, ":") &&
            lineNum);               HTTPMessage::expectHeaderToken(line, "Basic"))
           {
               // Suppress the user/passwd info
               HTTPMessage::skipHeaderWhitespace(line);
               for ( char* userpass = (char*)line ;
                   userpass < sep;
                   *userpass = 'X', userpass++);
  
         _trace(traceComponent,message,fmt,argList);              break;
           }
  
         va_end(argList);          line = sep + ((*sep == '\r') ? 2 : 1);
         delete []message;  
     }     }
   
       return requestBuf;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces method exit  //Traces method entry and exit
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_traceExit(  void Tracer::_traceMethod(
     const char* fileName,     const char* fileName,
     const Uint32 lineNum,     const Uint32 lineNum,
     const Uint32 traceComponent,     const Uint32 traceComponent,
     const char* fmt      const char* methodEntryExit,
     ...)      const char* method)
 { {
     va_list argList;  
     char* message;     char* message;
  
     if (_isTraceEnabled(traceComponent,LEVEL1))  
     {  
         va_start(argList,fmt);  
   
         //         //
         // Allocate memory for the message string         // Allocate memory for the message string
         // Needs to be updated if additional info is added         // Needs to be updated if additional info is added
         //         //
       // assume Method entry/exit string 15 characters long
       // +1 space character
         message = new char[ strlen(fileName) +         message = new char[ strlen(fileName) +
                             _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];          _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8
           + 16];
  
         sprintf(         sprintf(
            message,            message,
            "[%d:%s:%s:%u]: ",         "[%d:%s:%s:%u]: %s ",
            System::getPID(),            System::getPID(),
            Threads::id().buffer,            Threads::id().buffer,
            fileName,            fileName,
            lineNum);         lineNum,
          methodEntryExit);
  
         _trace(traceComponent,message,fmt,argList);      _traceCString(traceComponent, message, method);
         va_end(argList);  
  
         delete []message;         delete []message;
     }     }
 }  
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Checks if trace is enabled for the given component and level //Checks if trace is enabled for the given component and level
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::_isTraceEnabled(const Uint32 traceComponent,  Boolean Tracer::isTraceEnabled(
       const Uint32 traceComponent,
     const Uint32 traceLevel)     const Uint32 traceLevel)
 { {
     Tracer* instance = _getInstance();     Tracer* instance = _getInstance();
Line 401 
Line 279 
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Called by all trace interfaces to log message to trace file  //Called by all trace interfaces with variable arguments
   //to log message to trace file
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_trace( void Tracer::_trace(
     const Uint32 traceComponent,     const Uint32 traceComponent,
Line 420 
Line 299 
     // Needs to be updated if additional info is added     // Needs to be updated if additional info is added
     //     //
  
   
   
     // Construct the message header     // Construct the message header
     // The message header is in the following format     // The message header is in the following format
     // timestamp: <component name> [file name:line number]     // timestamp: <component name> [file name:line number]
     if (*message != '\0')     if (*message != '\0')
     {     {
        // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used in this format string         // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used
        msgHeader = new char [strlen(message)         // in this format string
                              + strlen(TRACE_COMPONENT_LIST[traceComponent])         msgHeader = new char [strlen(message) +
                              + strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];             strlen(TRACE_COMPONENT_LIST[traceComponent]) +
              strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];
  
         sprintf(msgHeader,"%s: %s %s",(const char*)timeStamp,         sprintf(msgHeader,"%s: %s %s",(const char*)timeStamp,
             TRACE_COMPONENT_LIST[traceComponent] ,message);             TRACE_COMPONENT_LIST[traceComponent] ,message);
         //delete [] msgHeader;  
     }     }
     else     else
     {     {
         //         //
         // Since the message is blank form a string using the pid and tid          // Since the message is blank, form a string using the pid and tid
         //         //
         char*  tmpBuffer;         char*  tmpBuffer;
  
Line 447 
Line 324 
         // Allocate messageHeader.         // Allocate messageHeader.
         // Needs to be updated if additional info is added         // Needs to be updated if additional info is added
         //         //
         tmpBuffer = new char[_STRLEN_MAX_PID_TID + 6];          tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6];
         sprintf(tmpBuffer, "[%u:%s]: ", System::getPID(), Threads::id().buffer);          sprintf(tmpBuffer, "[%u:%s]: ",
         msgHeader = new char [ strlen(timeStamp) + strlen(TRACE_COMPONENT_LIST[traceComponent]) +              System::getPID(), Threads::id().buffer);
           msgHeader = new char[strlen(timeStamp) +
               strlen(TRACE_COMPONENT_LIST[traceComponent]) +
                                strlen(tmpBuffer) + 1  + 5 ];                                strlen(tmpBuffer) + 1  + 5 ];
  
         sprintf(msgHeader,"%s: %s %s ",(const char*)timeStamp,         sprintf(msgHeader,"%s: %s %s ",(const char*)timeStamp,
             TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );             TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );
         delete []tmpBuffer;         delete []tmpBuffer;
         //delete [] msgHeader;  
   
     }     }
  
     // Call trace file handler to write message     // Call trace file handler to write message
Line 466 
Line 343 
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
   //Called by all trace interfaces using a character string without format string
   //to log message to trace file
   ////////////////////////////////////////////////////////////////////////////////
   void Tracer::_traceCString(
       const Uint32 traceComponent,
       const char* message,
       const char* cstring)
   {
       char* completeMessage;
   
       // Get the current system time and prepend to message
       String currentTime = System::getCurrentASCIITime();
       CString timeStamp = currentTime.getCString();
       //
       // Allocate completeMessage.
       // Needs to be updated if additional info is added
       //
   
       // Construct the message header
       // The message header is in the following format
       // timestamp: <component name> [file name:line number]
       if (*message != '\0')
       {
          // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used
          // in this format string
          completeMessage = new char [strlen(message) +
              strlen(TRACE_COMPONENT_LIST[traceComponent]) +
              strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5 +
              strlen(cstring) ];
   
           sprintf(completeMessage, "%s: %s %s%s", (const char*)timeStamp,
               TRACE_COMPONENT_LIST[traceComponent], message, cstring);
       }
       else
       {
           //
           // Since the message is blank, form a string using the pid and tid
           //
           char* tmpBuffer;
   
           //
           // Allocate messageHeader.
           // Needs to be updated if additional info is added
           //
           tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6];
           sprintf(tmpBuffer, "[%u:%s]: ",
               System::getPID(), Threads::id().buffer);
   
           completeMessage = new char[strlen(timeStamp) +
               strlen(TRACE_COMPONENT_LIST[traceComponent]) +
               strlen(tmpBuffer) + 1  + 5 +
               strlen(cstring)];
   
           sprintf(completeMessage, "%s: %s %s %s", (const char*)timeStamp,
               TRACE_COMPONENT_LIST[traceComponent], tmpBuffer, cstring);
           delete [] tmpBuffer;
       }
   
       // Call trace file handler to write message
       _getInstance()->_traceHandler->handleMessage(completeMessage);
   
       delete [] completeMessage;
   }
   
   
   ////////////////////////////////////////////////////////////////////////////////
 //Validate the trace file //Validate the trace file
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::isValidFileName(const char* filePath) Boolean Tracer::isValidFileName(const char* filePath)
Line 473 
Line 416 
     String moduleName = _getInstance()->_moduleName;     String moduleName = _getInstance()->_moduleName;
     if (moduleName == String::EMPTY)     if (moduleName == String::EMPTY)
     {     {
         return (_getInstance()->_traceHandler->isValidFilePath(filePath));          return
              _getInstance()->_traceHandler->isValidMessageDestination(filePath);
     }     }
     else     else
     {     {
         String extendedFilePath = String(filePath) + "." + moduleName;         String extendedFilePath = String(filePath) + "." + moduleName;
         return (_getInstance()->_traceHandler->isValidFilePath(          return _getInstance()->_traceHandler->isValidMessageDestination(
             extendedFilePath.getCString()));              extendedFilePath.getCString());
     }     }
 } }
  
Line 493 
Line 437 
 } }
  
 Boolean Tracer::isValidComponents( Boolean Tracer::isValidComponents(
     const String& traceComponents, String& invalidComponents)      const String& traceComponents,
       String& invalidComponents)
 { {
     // Validate the trace components and modify the traceComponents argument     // Validate the trace components and modify the traceComponents argument
     // to reflect the invalid components     // to reflect the invalid components
  
     Uint32    position=0;     Uint32    position=0;
     Uint32    index=0;     Uint32    index=0;
     String    componentName = String::EMPTY;      String    componentName;
     String    componentStr = String::EMPTY;      String    componentStr;
     Boolean   validComponent=false;     Boolean   validComponent=false;
     Boolean   retCode=true;     Boolean   retCode=true;
  
Line 513 
Line 458 
         // Check if ALL is specified         // Check if ALL is specified
         if (String::equalNoCase(componentStr,"ALL"))         if (String::equalNoCase(componentStr,"ALL"))
         {         {
             return _SUCCESS;              return true;
         }         }
  
         // Append _COMPONENT_SEPARATOR to the end of the traceComponents         // Append _COMPONENT_SEPARATOR to the end of the traceComponents
Line 560 
Line 505 
     else     else
     {     {
         // trace components is empty, it is a valid value so return true         // trace components is empty, it is a valid value so return true
         return _SUCCESS;          return true;
     }     }
   
     if ( invalidComponents != String::EMPTY )     if ( invalidComponents != String::EMPTY )
     {     {
         retCode = false;         retCode = false;
Line 575 
Line 521 
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
   //Validate the trace facility
   ////////////////////////////////////////////////////////////////////////////////
   Boolean Tracer::isValidTraceFacility(const String& traceFacility)
   {
       Boolean retCode = false;
   
       if (traceFacility.size() != 0)
       {
           Uint32 index = 0;
           while (TRACE_FACILITY_LIST[index] != 0 )
           {
               if (String::equalNoCase( traceFacility,TRACE_FACILITY_LIST[index]))
               {
                   retCode = true;
                   break;
               }
               index++;
           }
       }
   
       return retCode;
   }
   
   ////////////////////////////////////////////////////////////////////////////////
 //Set the name of the module being traced //Set the name of the module being traced
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::setModuleName(const String& moduleName) void Tracer::setModuleName(const String& moduleName)
Line 614 
Line 584 
     String moduleName = _getInstance()->_moduleName;     String moduleName = _getInstance()->_moduleName;
     if (moduleName == String::EMPTY)     if (moduleName == String::EMPTY)
     {     {
         return (_getInstance()->_traceHandler->setFileName(traceFile));          return _getInstance()->_traceHandler->setMessageDestination(traceFile);
     }     }
     else     else
     {     {
         String extendedTraceFile = String(traceFile) + "." + moduleName;         String extendedTraceFile = String(traceFile) + "." + moduleName;
         return (_getInstance()->_traceHandler->setFileName(          return _getInstance()->_traceHandler->setMessageDestination(
             extendedTraceFile.getCString()));              extendedTraceFile.getCString());
     }     }
 } }
  
Line 633 
Line 603 
  
     switch (traceLevel)     switch (traceLevel)
     {     {
           case LEVEL0:
               _getInstance()->_traceLevelMask = 0x00;
               break;
   
         case LEVEL1:         case LEVEL1:
             _getInstance()->_traceLevelMask = 0x01;             _getInstance()->_traceLevelMask = 0x01;
             break;             break;
Line 649 
Line 623 
             _getInstance()->_traceLevelMask = 0x0F;             _getInstance()->_traceLevelMask = 0x0F;
             break;             break;
  
           case LEVEL5:
               _getInstance()->_traceLevelMask = 0x1F;
               break;
   
         default:         default:
             _getInstance()->_traceLevelMask = 0;              _getInstance()->_traceLevelMask = 0x00;
             retCode = 1;             retCode = 1;
     }     }
   
       if (_getInstance()->_componentsAreSet &&
           _getInstance()->_traceLevelMask )
       {
           _traceOn = true;
       }
       else
       {
           _traceOn = false;
       }
   
     return retCode;     return retCode;
 } }
  
Line 661 
Line 650 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::setTraceComponents(const String& traceComponents) void Tracer::setTraceComponents(const String& traceComponents)
 { {
     Uint32 position          = 0;      Tracer* instance = _getInstance();
     Uint32 index             = 0;  
     String componentName     = String::EMPTY;  
     String componentStr      = traceComponents;  
     String invalidComponents = String::EMPTY;  
  
     if (componentStr != String::EMPTY)  
     {  
         // Check if ALL is specified         // Check if ALL is specified
         if (String::equalNoCase(componentStr,"ALL"))      if (String::equalNoCase(traceComponents,"ALL"))
         {         {
             for (index=0; index < _NUM_COMPONENTS;          for (Uint32 index = 0; index < _NUM_COMPONENTS; index++)
                     (_getInstance()->_traceComponentMask.get())[index++] = true);          {
             _traceOn = true;              (instance->_traceComponentMask.get())[index] = true;
           }
   
           instance->_componentsAreSet=true;
   
           // If tracing isn't turned off by a traceLevel of zero, let's
           // turn on the flag that activates tracing.
           _traceOn = (instance->_traceLevelMask != LEVEL0);
   
             return ;             return ;
         }         }
  
         // initialise ComponentMask array to False      // initialize ComponentMask array to False
         for (index = 0;index < _NUM_COMPONENTS;      for (Uint32 index = 0; index < _NUM_COMPONENTS; index++)
               (_getInstance()->_traceComponentMask.get())[index++] = false);      {
           (instance->_traceComponentMask.get())[index] = false;
       }
         _traceOn = false;         _traceOn = false;
       instance->_componentsAreSet=false;
   
       if (traceComponents != String::EMPTY)
       {
           Uint32 index = 0;
           Uint32 position = 0;
           String componentName;
           String componentStr = traceComponents;
   
  
         // Append _COMPONENT_SEPARATOR to the end of the traceComponents         // Append _COMPONENT_SEPARATOR to the end of the traceComponents
         componentStr.append(_COMPONENT_SEPARATOR);         componentStr.append(_COMPONENT_SEPARATOR);
Line 700 
Line 702 
                 if (String::equalNoCase(                 if (String::equalNoCase(
                     componentName,TRACE_COMPONENT_LIST[index]))                     componentName,TRACE_COMPONENT_LIST[index]))
                 {                 {
                     (_getInstance()->_traceComponentMask.get())[index]=true;                      (instance->_traceComponentMask.get())[index] = true;
                     _traceOn = true;  
                       instance->_componentsAreSet=true;
  
                     // Found component, break from the loop                     // Found component, break from the loop
                     break;                     break;
Line 715 
Line 718 
             // Remove the searched componentname from the traceComponents             // Remove the searched componentname from the traceComponents
             componentStr.remove(0,position+1);             componentStr.remove(0,position+1);
         }         }
   
           // If one of the components was set for tracing and the traceLevel
           // is not zero, then turn on tracing.
           _traceOn = (instance->_componentsAreSet &&
                      (instance->_traceLevelMask != LEVEL0));
     }     }
     else  
     {  
         // initialise ComponentMask array to False  
         for (Uint32 index = 0;index < _NUM_COMPONENTS;  
                  (_getInstance()->_traceComponentMask.get())[index++] = false);  
         _traceOn = 0;  
     }  
     return ;     return ;
 } }
  
 void Tracer::traceEnter(TracerToken& token, Uint32 traceComponent, const char* method)  ////////////////////////////////////////////////////////////////////////////////
 {  // Set the trace facility to be used
     if (_traceOn)  ////////////////////////////////////////////////////////////////////////////////
   Uint32 Tracer::setTraceFacility(const String& traceFacility)
     {     {
         token.component = traceComponent;      Uint32 retCode = 0;
         token.method = method;      Tracer* instance = _getInstance();
  
         //Tracer::traceEnter("unknown", 0, component, method);      if (traceFacility.size() != 0)
         _traceEnter( "unknown", 0, traceComponent, "%s %s",      {
                      _METHOD_ENTER_MSG, method);          Uint32 index = 0;
           while (TRACE_FACILITY_LIST[index] != 0 )
           {
               if (String::equalNoCase( traceFacility,TRACE_FACILITY_LIST[index]))
               {
                   if (index != instance->_traceFacility)
                   {
                       instance->_traceFacility = index;
                       instance->_traceHandler.reset(
                           instance->getTraceHandler(instance->_traceFacility));
                   }
                   retCode = 1;
                   break;
               }
               index++;
     }     }
 } }
  
 void Tracer::traceExit(TracerToken& token)      return retCode;
 {  }
     if (_traceOn)  
  
         // KS Tracer::traceExit("unknown", 0, token.component, token.method);  ////////////////////////////////////////////////////////////////////////////////
         _traceExit( "unknown",0, token.component, "%s %s",  // Get the trace facility in use
             _METHOD_EXIT_MSG, token.method);  ////////////////////////////////////////////////////////////////////////////////
   Uint32 Tracer::getTraceFacility()
   {
       return _getInstance()->_traceFacility;
 } }
  
 void Tracer::traceEnter( void Tracer::traceEnter(
Line 755 
Line 774 
     Uint32 traceComponent,     Uint32 traceComponent,
     const char* method)     const char* method)
 { {
     if (_traceOn)  
     {  
         token.component = traceComponent;         token.component = traceComponent;
         token.method = method;         token.method = method;
  
         //Tracer::traceEnter(file, line, component, method);      if (isTraceEnabled(traceComponent, LEVEL5))
         _traceEnter( file, line, traceComponent, "%s %s",      {
           _traceMethod(
               file, (Uint32)line, traceComponent,
                      _METHOD_ENTER_MSG, method);                      _METHOD_ENTER_MSG, method);
     }     }
 } }
Line 771 
Line 790 
     const char* file,     const char* file,
     size_t line)     size_t line)
 { {
     if (_traceOn)      if (isTraceEnabled(token.component, LEVEL5) && token.method)
         //Tracer::traceExit(file, line, token.component, token.method);          _traceMethod(
         _traceExit( file, line, token.component, "%s %s",              file, (Uint32)line, token.component,
                 _METHOD_EXIT_MSG, token.method);                 _METHOD_EXIT_MSG, token.method);
 } }
  
 void Tracer::traceBuffer(  ////////////////////////////////////////////////////////////////////////////////
     const Uint32 traceComponent,  //Traces the given string - Overloaded to include the fileName and line number
     const Uint32 traceLevel,  //of trace origin.
     const char*  data,  ////////////////////////////////////////////////////////////////////////////////
     const Uint32 size)  void Tracer::traceCString(
 {  
     if (_traceOn)  
         _traceBuffer( traceComponent, traceLevel, data, size );  
 }  
   
 void Tracer::traceBuffer(  
     const char*  fileName,  
     const Uint32 lineNum,  
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char*  data,  
     const Uint32 size)  
 {  
     if (_traceOn)  
     {  
         _traceBuffer( fileName, lineNum,  
                       traceComponent, traceLevel, data, size );  
     }  
 }  
   
 void Tracer::trace(  
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char *fmt,  
     ...)  
 {  
     if (_traceOn)  
     {  
         va_list argList;  
   
         va_start(argList,fmt);  
         _trace(traceComponent,traceLevel,fmt,argList);  
         va_end(argList);  
     }  
 }  
   
 void Tracer::trace(  
     const char* fileName,     const char* fileName,
     const Uint32 lineNum,     const Uint32 lineNum,
     const Uint32 traceComponent,     const Uint32 traceComponent,
     const Uint32 traceLevel,      const char* cstring)
     const char* fmt,  
     ...)  
 {  
     if (_traceOn)  
     {     {
         va_list argList;      char* message;
  
         va_start(argList,fmt);      //
         _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList);      // Allocate memory for the message string
         va_end(argList);      // Needs to be updated if additional info is added
     }      //
 }      message = new char[strlen(fileName) +
           _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8];
       sprintf(
           message,
           "[%d:%s:%s:%u]: ",
           System::getPID(),
           Threads::id().buffer,
           fileName,
           lineNum);
  
 void Tracer::trace(      _traceCString(traceComponent, message, cstring);
     const char*   fileName,      delete [] message;
     const Uint32  lineNum,  
     const Uint32  traceComponent,  
     const Uint32  traceLevel,  
     const String& traceString)  
 {  
     if (_traceOn)  
     {  
         _traceString( fileName, lineNum, traceComponent, traceLevel,  
                       traceString );  
     }  
 } }
  
 void Tracer::traceCIMException( void Tracer::traceCIMException(
     const Uint32  traceComponent,     const Uint32  traceComponent,
     const Uint32  traceLevel,     const Uint32  traceLevel,
     CIMException  cimException)      const CIMException& cimException)
 { {
     if (_traceOn)      if (isTraceEnabled(traceComponent, traceLevel))
     {     {
         _traceCIMException( traceComponent, traceLevel, cimException );          _traceCIMException(traceComponent, cimException);
     }  
 } }
   
 void Tracer::trace(  
     const Uint32  traceComponent,  
     const Uint32  level,  
     const String& string)  
 {  
     trace("unknown", 0, traceComponent, level, string);  
 } }
  
 #endif /* !PEGASUS_REMOVE_TRACE */ #endif /* !PEGASUS_REMOVE_TRACE */


Legend:
Removed from v.1.38  
changed lines
  Added in v.1.50

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2