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

Diff for /pegasus/src/Pegasus/Common/Logger.cpp between version 1.56 and 1.62

version 1.56, 2007/09/12 21:30:58 version 1.62, 2008/08/12 18:26:27
Line 35 
Line 35 
 #include <fstream> #include <fstream>
 #include <cstring> #include <cstring>
 #include <Pegasus/Common/Logger.h> #include <Pegasus/Common/Logger.h>
   #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
 #include <Pegasus/Common/MessageLoader.h> #include <Pegasus/Common/MessageLoader.h>
Line 72 
Line 73 
  
 const Uint32 Logger::_NUM_LOGLEVEL = 5; const Uint32 Logger::_NUM_LOGLEVEL = 5;
  
 // Set separator  
 const char Logger::_SEPARATOR = '@';  
   
 Uint32 Logger::_severityMask; Uint32 Logger::_severityMask;
  
 Uint32 Logger::_writeControlMask = 0xF;   // Set all on by default  ///////////////////////////////////////////////////////////////////////////////
   //
   // LoggerRep
   //
   ///////////////////////////////////////////////////////////////////////////////
   
   #if defined(PEGASUS_USE_SYSLOGS)
  
 // Set the return codes  class LoggerRep
 const Boolean Logger::_SUCCESS = 1;  {
 const Boolean Logger::_FAILURE = 0;  public:
   
       LoggerRep(const String& homeDirectory)
       {
   # ifdef PEGASUS_OS_ZOS
           logIdentity = strdup(System::CIMSERVER.getCString());
           // If System Log is used open it
           System::openlog(logIdentity, LOG_PID, LOG_DAEMON);
   # endif
       }
   
       ~LoggerRep()
       {
   # ifdef PEGASUS_OS_ZOS
           System::closelog();
           free(logIdentity);
   # endif
       }
   
       // Actual logging is done in this routine
       void log(Logger::LogFileType logFileType,
           const String& systemId,
           Uint32 logLevel,
           const String localizedMsg)
       {
           // Log the message
           System::syslog(systemId, logLevel, localizedMsg.getCString());
       }
   
   private:
   
   # ifdef PEGASUS_OS_ZOS
       char* logIdentity;
   # endif
   };
   
   #else    // !defined(PEGASUS_USE_SYSLOGS)
  
     static const char* fileNames[] =     static const char* fileNames[] =
     {     {
         "PegasusTrace.log",         "PegasusTrace.log",
         "PegasusStandard.log",         "PegasusStandard.log",
         "PegasusAudit.log",         "PegasusAudit.log",
         "PegasusError.log",      "PegasusError.log"
         "PegasusDebug.log"  
     };     };
 static const char* lockFileName =  "PegasusLog.lock"; static const char* lockFileName =  "PegasusLog.lock";
  
   /*
 /* _constructFileName prepares the absolute file name from homeDirectory      _constructFileName builds the absolute file name from homeDirectory
     and fileName.     and fileName.
   
     Today this is static.  However, it should be completely  
     configerable and driven from the config file so that  
     Log organization and names are open.  
     ATTN: rewrite this so that names, choice to do logs and  
     mask for level of severity are all driven from configuration  
     input.  
 */ */
 static CString _constructFileName( static CString _constructFileName(
     const String& homeDirectory,     const String& homeDirectory,
     const char * fileName)     const char * fileName)
 { {
     String result;     String result;
     result.reserveCapacity((Uint32)(homeDirectory.size() + 1 +      result.reserveCapacity(
         strlen(fileName)));          (Uint32)(homeDirectory.size() + 1 + strlen(fileName)));
     result.append(homeDirectory);     result.append(homeDirectory);
     result.append('/');     result.append('/');
     result.append(fileName);     result.append(fileName);
Line 123 
Line 155 
  
     LoggerRep(const String& homeDirectory)     LoggerRep(const String& homeDirectory)
     {     {
 #if !defined(PEGASUS_USE_SYSLOGS)  
         // Add test for home directory set.         // Add test for home directory set.
  
         // If home directory does not exist, create it.         // If home directory does not exist, create it.
Line 156 
Line 187 
         }         }
 #endif #endif
  
   
         _logFileNames[Logger::TRACE_LOG] = _constructFileName(homeDirectory,         _logFileNames[Logger::TRACE_LOG] = _constructFileName(homeDirectory,
                                                fileNames[Logger::TRACE_LOG]);                                                fileNames[Logger::TRACE_LOG]);
  
Line 170 
Line 200 
  
         _logFileNames[Logger::ERROR_LOG] = _constructFileName(homeDirectory,         _logFileNames[Logger::ERROR_LOG] = _constructFileName(homeDirectory,
                                                fileNames[Logger::ERROR_LOG]);                                                fileNames[Logger::ERROR_LOG]);
   
         _logFileNames[Logger::DEBUG_LOG] = _constructFileName(homeDirectory,  
                                                fileNames[Logger::DEBUG_LOG]);  
 #else  
   
 #ifdef PEGASUS_OS_ZOS  
        logIdentity = strdup(System::CIMSERVER.getCString());  
         // If System Log is used open it  
         System::openlog(logIdentity, LOG_PID, LOG_DAEMON);  
 #endif  
   
 #endif  
   
     }     }
  
     ~LoggerRep()     ~LoggerRep()
     {     {
   
 #ifdef PEGASUS_OS_ZOS  
         System::closelog();  
         free(logIdentity);  
 #endif  
     }     }
  
     // Actual logging is done in this routine     // Actual logging is done in this routine
Line 200 
Line 212 
         Uint32 logLevel,         Uint32 logLevel,
         const String localizedMsg)         const String localizedMsg)
     {     {
 #if defined(PEGASUS_USE_SYSLOGS)  
   
         // Log the message  
         System::syslog(systemId, logLevel, localizedMsg.getCString());  
   
 #else  
         // Prepend the systemId to the incoming message         // Prepend the systemId to the incoming message
         String messageString(systemId);         String messageString(systemId);
         messageString.append(": ");         messageString.append(": ");
Line 276 
Line 282 
         logFileStream << System::getCurrentASCIITime()         logFileStream << System::getCurrentASCIITime()
            << " " << tmp << (const char *)messageString.getCString() << endl;            << " " << tmp << (const char *)messageString.getCString() << endl;
         logFileStream.close();         logFileStream.close();
 #endif // ifndef PEGASUS_USE_SYSLOGS  
     }     }
  
 private: private:
  
 #ifdef PEGASUS_OS_ZOS  
     char* logIdentity;  
 #endif  
     CString _logFileNames[int(Logger::NUM_LOGS)];     CString _logFileNames[int(Logger::NUM_LOGS)];
   
 #ifndef PEGASUS_OS_VMS #ifndef PEGASUS_OS_VMS
     CString _loggerLockFileName;     CString _loggerLockFileName;
     Mutex _mutex;     Mutex _mutex;
 #endif #endif
 }; };
  
   #endif    // !defined(PEGASUS_USE_SYSLOGS)
   
   
   ///////////////////////////////////////////////////////////////////////////////
   //
   // Logger
   //
   ///////////////////////////////////////////////////////////////////////////////
   
 void Logger::_putInternal( void Logger::_putInternal(
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     const Uint32 logComponent, // FUTURE: Support logComponent mask     const Uint32 logComponent, // FUTURE: Support logComponent mask
     Uint32 logLevel,     Uint32 logLevel,
     const String& formatString,     const String& formatString,
     const String& messageId,      const char* messageId,
     const Formatter::Arg& arg0,     const Formatter::Arg& arg0,
     const Formatter::Arg& arg1,     const Formatter::Arg& arg1,
     const Formatter::Arg& arg2,     const Formatter::Arg& arg2,
Line 323 
Line 335 
  
         // If the caller specified a messageId, then load the localized         // If the caller specified a messageId, then load the localized
         // message in the locale of the server process.         // message in the locale of the server process.
         if (messageId != String::EMPTY)          if (messageId)
         {         {
             // A message ID was specified.  Use the MessageLoader.             // A message ID was specified.  Use the MessageLoader.
             MessageLoaderParms msgParms(messageId, formatString);             MessageLoaderParms msgParms(messageId, formatString);
Line 348 
Line 360 
         }         }
 // l10n end // l10n end
  
   
        // Call the actual logging routine is in LoggerRep.        // Call the actual logging routine is in LoggerRep.
        _rep->log(logFileType, systemId, logLevel, localizedMsg);        _rep->log(logFileType, systemId, logLevel, localizedMsg);
   
          // route log message to trace too -> component LogMessages
          if (Logger::TRACE_LOG != logFileType)
          {
              // do not write log message to trace when trace facility is
              // the log to avoid double messages
              if (Tracer::TRACE_FACILITY_LOG != Tracer::getTraceFacility())
              {
                  PEG_TRACE_CSTRING(
                      TRC_LOGMSG,
                      Tracer::LEVEL1,
                      (const char*) localizedMsg.getCString());
              }
          }
     }     }
 } }
  
Line 379 
Line 404 
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,         Logger::_putInternal(logFileType, systemId, 0, logLevel,
             formatString, String::EMPTY, arg0, arg1, arg2, arg3,              formatString, 0, arg0, arg1, arg2, arg3,
             arg4, arg5, arg6, arg7, arg8, arg9);             arg4, arg5, arg6, arg7, arg8, arg9);
     }     }
 } }
Line 393 
Line 418 
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,         Logger::_putInternal(logFileType, systemId, 0, logLevel,
             formatString, String::EMPTY);              formatString, 0);
     }     }
 } }
  
Line 407 
Line 432 
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,         Logger::_putInternal(logFileType, systemId, 0, logLevel,
             formatString, String::EMPTY, arg0);              formatString, 0, arg0);
     }     }
 } }
  
Line 422 
Line 447 
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,         Logger::_putInternal(logFileType, systemId, 0, logLevel,
             formatString, String::EMPTY, arg0, arg1);              formatString, 0, arg0, arg1);
     }     }
 } }
  
Line 438 
Line 463 
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,         Logger::_putInternal(logFileType, systemId, 0, logLevel,
             formatString, String::EMPTY, arg0, arg1, arg2);              formatString, 0, arg0, arg1, arg2);
     }     }
 } }
  
Line 446 
Line 471 
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     Uint32 logLevel,     Uint32 logLevel,
     const String& messageId,      const char* messageId,
     const String& formatString,      const char* formatString,
     const Formatter::Arg& arg0,     const Formatter::Arg& arg0,
     const Formatter::Arg& arg1,     const Formatter::Arg& arg1,
     const Formatter::Arg& arg2,     const Formatter::Arg& arg2,
Line 471 
Line 496 
      LogFileType logFileType,      LogFileType logFileType,
      const String& systemId,      const String& systemId,
      Uint32 logLevel,      Uint32 logLevel,
      const String& messageId,       const char* messageId,
      const String& formatString)       const char* formatString)
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
Line 485 
Line 510 
      LogFileType logFileType,      LogFileType logFileType,
      const String& systemId,      const String& systemId,
      Uint32 logLevel,      Uint32 logLevel,
      const String& messageId,       const char* messageId,
      const String& formatString,       const char* formatString,
      const Formatter::Arg& arg0)      const Formatter::Arg& arg0)
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
Line 500 
Line 525 
      LogFileType logFileType,      LogFileType logFileType,
      const String& systemId,      const String& systemId,
      Uint32 logLevel,      Uint32 logLevel,
      const String& messageId,       const char* messageId,
      const String& formatString,       const char* formatString,
      const Formatter::Arg& arg0,      const Formatter::Arg& arg0,
      const Formatter::Arg& arg1)      const Formatter::Arg& arg1)
 { {
Line 516 
Line 541 
      LogFileType logFileType,      LogFileType logFileType,
      const String& systemId,      const String& systemId,
      Uint32 logLevel,      Uint32 logLevel,
      const String& messageId,       const char* messageId,
      const String& formatString,       const char* formatString,
      const Formatter::Arg& arg0,      const Formatter::Arg& arg0,
      const Formatter::Arg& arg1,      const Formatter::Arg& arg1,
      const Formatter::Arg& arg2)      const Formatter::Arg& arg2)
Line 533 
Line 558 
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     const Uint32 logComponent,     const Uint32 logComponent,
     const String& formatString,      const String& message)
     const Formatter::Arg& arg0,  
     const Formatter::Arg& arg1,  
     const Formatter::Arg& arg2,  
     const Formatter::Arg& arg3,  
     const Formatter::Arg& arg4,  
     const Formatter::Arg& arg5,  
     const Formatter::Arg& arg6,  
     const Formatter::Arg& arg7,  
     const Formatter::Arg& arg8,  
     const Formatter::Arg& arg9)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, String::EMPTY, arg0, arg1, arg2, arg3, arg4, arg5,  
             arg6, arg7, arg8, arg9);  
     }  
 }  
   
 void Logger::trace(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& formatString)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, String::EMPTY);  
     }  
 }  
   
 void Logger::trace(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& formatString,  
     const Formatter::Arg& arg0)  
 { {
     if (wouldLog(Logger::TRACE))     if (wouldLog(Logger::TRACE))
     {     {
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,
             formatString, String::EMPTY, arg0);              message, 0);
     }  
 }  
   
 void Logger::trace(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& formatString,  
     const Formatter::Arg& arg0,  
     const Formatter::Arg& arg1)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, String::EMPTY, arg0, arg1);  
     }  
 }  
   
 void Logger::trace(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& formatString,  
     const Formatter::Arg& arg0,  
     const Formatter::Arg& arg1,  
     const Formatter::Arg& arg2)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, String::EMPTY, arg0, arg1, arg2);  
     }  
 }  
   
 void Logger::trace_l(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& messageId,  
     const String& formatString,  
     const Formatter::Arg& arg0,  
     const Formatter::Arg& arg1,  
     const Formatter::Arg& arg2,  
     const Formatter::Arg& arg3,  
     const Formatter::Arg& arg4,  
     const Formatter::Arg& arg5,  
     const Formatter::Arg& arg6,  
     const Formatter::Arg& arg7,  
     const Formatter::Arg& arg8,  
     const Formatter::Arg& arg9)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, messageId, arg0, arg1, arg2, arg3, arg4, arg5, arg6,  
             arg7, arg8, arg9);  
     }  
 }  
   
 void Logger::trace_l(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& messageId,  
     const String& formatString)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, messageId);  
     }  
 }  
   
 void Logger::trace_l(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& messageId,  
     const String& formatString,  
     const Formatter::Arg& arg0)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, messageId, arg0);  
     }  
 }  
   
 void Logger::trace_l(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& messageId,  
     const String& formatString,  
     const Formatter::Arg& arg0,  
     const Formatter::Arg& arg1)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, messageId, arg0, arg1);  
     }  
 }  
   
 void Logger::trace_l(  
     LogFileType logFileType,  
     const String& systemId,  
     const Uint32 logComponent,  
     const String& messageId,  
     const String& formatString,  
     const Formatter::Arg& arg0,  
     const Formatter::Arg& arg1,  
     const Formatter::Arg& arg2)  
 {  
     if (wouldLog(Logger::TRACE))  
     {  
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,  
             formatString, messageId, arg0, arg1, arg2);  
     }     }
 } }
  
Line 799 
Line 668 
     else     else
     {     {
         // logLevels is empty, it is a valid value so return true         // logLevels is empty, it is a valid value so return true
         return _SUCCESS;          return true;
     }     }
  
     return validlogLevel;     return validlogLevel;


Legend:
Removed from v.1.56  
changed lines
  Added in v.1.62

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2