(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.62 and 1.71

version 1.62, 2008/08/12 18:26:27 version 1.71, 2013/04/09 05:53:13
Line 1 
Line 1 
 //%2006////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development  // Licensed to The Open Group (TOG) under one or more contributor license
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;  // this work for additional information regarding copyright ownership.
 // IBM Corp.; EMC Corporation, The Open Group.  // Each contributor licenses this file to you under the OpenPegasus Open
 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;  // Source License; you may not use this file except in compliance with the
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.  // License.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;  //
 // EMC Corporation; VERITAS Software Corporation; The Open Group.  // Permission is hereby granted, free of charge, to any person obtaining a
 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;  // copy of this software and associated documentation files (the "Software"),
 // EMC Corporation; Symantec Corporation; The Open Group.  // to deal in the Software without restriction, including without limitation
 //  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 // Permission is hereby granted, free of charge, to any person obtaining a copy  // and/or sell copies of the Software, and to permit persons to whom the
 // of this software and associated documentation files (the "Software"), to  // Software is furnished to do so, subject to the following conditions:
 // deal in the Software without restriction, including without limitation the  //
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  // The above copyright notice and this permission notice shall be included
 // sell copies of the Software, and to permit persons to whom the Software is  // in all copies or substantial portions of the Software.
 // furnished to do so, subject to the following conditions:  //
 //  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
 // //
 //==============================================================================  //////////////////////////////////////////////////////////////////////////
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 50 
Line 48 
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 // Maximum logfile size is defined as 32 MB = 32 * 1024 * 1024  
 # define PEGASUS_MAX_LOGFILE_SIZE 0X2000000  
  
 const Uint32 Logger::TRACE = (1 << 0); const Uint32 Logger::TRACE = (1 << 0);
 const Uint32 Logger::INFORMATION = (1 << 1); const Uint32 Logger::INFORMATION = (1 << 1);
Line 75 
Line 71 
  
 Uint32 Logger::_severityMask; Uint32 Logger::_severityMask;
  
   
 /////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
 // //
 // LoggerRep // LoggerRep
Line 87 
Line 84 
 { {
 public: public:
  
     LoggerRep(const String& homeDirectory)      LoggerRep(const String&)
     {     {
 # ifdef PEGASUS_OS_ZOS # ifdef PEGASUS_OS_ZOS
         logIdentity = strdup(System::CIMSERVER.getCString());         logIdentity = strdup(System::CIMSERVER.getCString());
Line 105 
Line 102 
     }     }
  
     // Actual logging is done in this routine     // Actual logging is done in this routine
     void log(Logger::LogFileType logFileType,      void log(Logger::LogFileType,
         const String& systemId,         const String& systemId,
         Uint32 logLevel,         Uint32 logLevel,
         const String localizedMsg)         const String localizedMsg)
Line 210 
Line 207 
     void log(Logger::LogFileType logFileType,     void log(Logger::LogFileType logFileType,
         const String& systemId,         const String& systemId,
         Uint32 logLevel,         Uint32 logLevel,
         const String localizedMsg)          const String &localizedMsg)
     {     {
         // Prepend the systemId to the incoming message         // Prepend the systemId to the incoming message
         String messageString(systemId);         String messageString(systemId);
Line 240 
Line 237 
         FileSystem::getFileSize(String(_logFileNames[logFileType]),         FileSystem::getFileSize(String(_logFileNames[logFileType]),
                                        logFileSize);                                        logFileSize);
  
         // Check if the size of the logfile is exceeding 32MB.          // Check if the size of the logfile is exceeding _maxLogFileSizeBytes.
         if ( logFileSize > PEGASUS_MAX_LOGFILE_SIZE)          if ( logFileSize > _maxLogFileSizeBytes)
         {         {
             // Prepare appropriate file name based on the logFileType.             // Prepare appropriate file name based on the logFileType.
             // Eg: if Logfile name is PegasusStandard.log, pruned logfile name             // Eg: if Logfile name is PegasusStandard.log, pruned logfile name
Line 256 
Line 253 
             // info to the file name.             // info to the file name.
  
             String timeStamp = System::getCurrentASCIITime();             String timeStamp = System::getCurrentASCIITime();
             for (unsigned int i=0; i<=timeStamp.size(); i++)              for ( unsigned int i = 0; i < timeStamp.size(); i++ )
             {             {
                 if(timeStamp[i] == '/' || timeStamp[i] == ':')                 if(timeStamp[i] == '/' || timeStamp[i] == ':')
                 {                 {
Line 284 
Line 281 
         logFileStream.close();         logFileStream.close();
     }     }
  
       static void setMaxLogFileSize(Uint32 maxLogFileSizeBytes)
       {
           _maxLogFileSizeBytes = maxLogFileSizeBytes;
       }
 private: private:
  
     CString _logFileNames[int(Logger::NUM_LOGS)];     CString _logFileNames[int(Logger::NUM_LOGS)];
  
       static Uint32 _maxLogFileSizeBytes;
 # ifndef PEGASUS_OS_VMS # ifndef PEGASUS_OS_VMS
     CString _loggerLockFileName;     CString _loggerLockFileName;
     Mutex _mutex;     Mutex _mutex;
 # endif # endif
 }; };
  
   Uint32 LoggerRep::_maxLogFileSizeBytes;
   
 #endif    // !defined(PEGASUS_USE_SYSLOGS) #endif    // !defined(PEGASUS_USE_SYSLOGS)
  
  
Line 306 
Line 310 
 void Logger::_putInternal( void Logger::_putInternal(
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     const Uint32 logComponent, // FUTURE: Support logComponent mask  
     Uint32 logLevel,     Uint32 logLevel,
     const String& formatString,      const String& message)
     const char* messageId,  
     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)  
 {  
     // Test for logLevel against severity mask to determine  
     // if we write this log.  
     if ((_severityMask & logLevel) != 0)  
     {     {
         if (!_rep)         if (!_rep)
            _rep = new LoggerRep(_homeDirectory);            _rep = new LoggerRep(_homeDirectory);
  
   
         // l10n start  
         // The localized message to be sent to the system log.  
         String localizedMsg;  
   
         // If the caller specified a messageId, then load the localized  
         // message in the locale of the server process.  
         if (messageId)  
         {  
             // A message ID was specified.  Use the MessageLoader.  
             MessageLoaderParms msgParms(messageId, formatString);  
             msgParms.useProcessLocale = true;  
             msgParms.arg0 = arg0;  
             msgParms.arg1 = arg1;  
             msgParms.arg2 = arg2;  
             msgParms.arg3 = arg3;  
             msgParms.arg4 = arg4;  
             msgParms.arg5 = arg5;  
             msgParms.arg6 = arg6;  
             msgParms.arg7 = arg7;  
             msgParms.arg8 = arg8;  
             msgParms.arg9 = arg9;  
   
             localizedMsg = MessageLoader::getMessage(msgParms);  
         }  
         else  
         {  // No message ID.  Use the Pegasus formatter  
               localizedMsg = Formatter::format(formatString,  
                 arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);  
         }  
 // 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, message);
  
        // route log message to trace too -> component LogMessages      // PEP 315
       // The trace can be routed into the log. The logged trace messages are
       // logged with logFileType of Logger::TRACE_LOG.
       // To avoid a cirular writing of these messages, log messages with
       // logFileType of Logger::TRACE_LOG are never send to the trace.
        if (Logger::TRACE_LOG != logFileType)        if (Logger::TRACE_LOG != logFileType)
        {        {
            // do not write log message to trace when trace facility is          // For all other logFileType's send the log messages to the trace.
            // the log to avoid double messages          // But do not write log messages to trace when the trace facility is
           // set to log. This avoids double messages.
            if (Tracer::TRACE_FACILITY_LOG != Tracer::getTraceFacility())            if (Tracer::TRACE_FACILITY_LOG != Tracer::getTraceFacility())
            {            {
                PEG_TRACE_CSTRING(                PEG_TRACE_CSTRING(
                    TRC_LOGMSG,                    TRC_LOGMSG,
                    Tracer::LEVEL1,                    Tracer::LEVEL1,
                    (const char*) localizedMsg.getCString());                  (const char*) message.getCString());
            }  
        }        }
     }     }
 } }
Line 403 
Line 363 
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,          Logger::_putInternal(logFileType, systemId, logLevel,
             formatString, 0, arg0, arg1, arg2, arg3,              Formatter::format(formatString, arg0, arg1, arg2, arg3,
             arg4, arg5, arg6, arg7, arg8, arg9);                  arg4, arg5, arg6, arg7, arg8, arg9));
     }     }
 } }
  
Line 417 
Line 377 
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,          Logger::_putInternal(logFileType, systemId, logLevel, formatString);
             formatString, 0);  
     }     }
 } }
  
Line 431 
Line 390 
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,          Logger::_putInternal(logFileType, systemId, logLevel,
             formatString, 0, arg0);              Formatter::format(formatString, arg0));
     }     }
 } }
  
Line 446 
Line 405 
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,          Logger::_putInternal(logFileType, systemId, logLevel,
             formatString, 0, arg0, arg1);              Formatter::format(formatString, arg0, arg1));
     }     }
 } }
  
Line 462 
Line 421 
 { {
     if (wouldLog(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,          Logger::_putInternal(logFileType, systemId, logLevel,
             formatString, 0, arg0, arg1, arg2);              Formatter::format(formatString, arg0, arg1, arg2));
     }     }
 } }
  
Line 471 
Line 430 
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     Uint32 logLevel,     Uint32 logLevel,
     const char* messageId,      const MessageLoaderParms& msgParms)
     const char* 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(logLevel))     if (wouldLog(logLevel))
     {     {
         Logger::_putInternal(logFileType, systemId, 0, logLevel,          MessageLoaderParms parms = msgParms;
             formatString, messageId, arg0, arg1, arg2, arg3, arg4, arg5,          parms.useProcessLocale = true;
             arg6, arg7, arg8, arg9);          Logger::_putInternal(logFileType, systemId, logLevel,
     }              MessageLoader::getMessage(parms));
 }  
   
 void Logger::put_l(  
      LogFileType logFileType,  
      const String& systemId,  
      Uint32 logLevel,  
      const char* messageId,  
      const char* formatString)  
 {  
     if (wouldLog(logLevel))  
     {  
         Logger::_putInternal(logFileType, systemId, 0, logLevel,  
         formatString, messageId);  
     }  
 }  
   
 void Logger::put_l(  
      LogFileType logFileType,  
      const String& systemId,  
      Uint32 logLevel,  
      const char* messageId,  
      const char* formatString,  
      const Formatter::Arg& arg0)  
 {  
     if (wouldLog(logLevel))  
     {  
         Logger::_putInternal(logFileType, systemId, 0, logLevel,  
             formatString, messageId, arg0);  
     }  
 }  
   
 void Logger::put_l(  
      LogFileType logFileType,  
      const String& systemId,  
      Uint32 logLevel,  
      const char* messageId,  
      const char* formatString,  
      const Formatter::Arg& arg0,  
      const Formatter::Arg& arg1)  
 {  
     if (wouldLog(logLevel))  
     {  
         Logger::_putInternal(logFileType, systemId, 0, logLevel,  
             formatString, messageId, arg0, arg1);  
     }  
 }  
   
 void Logger::put_l(  
      LogFileType logFileType,  
      const String& systemId,  
      Uint32 logLevel,  
      const char* messageId,  
      const char* formatString,  
      const Formatter::Arg& arg0,  
      const Formatter::Arg& arg1,  
      const Formatter::Arg& arg2)  
 {  
     if (wouldLog(logLevel))  
     {  
         Logger::_putInternal(logFileType, systemId, 0, logLevel,  
             formatString, messageId, arg0, arg1, arg2);  
     }     }
 } }
  
 void Logger::trace( void Logger::trace(
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     const Uint32 logComponent,  
     const String& message)     const String& message)
 { {
     if (wouldLog(Logger::TRACE))     if (wouldLog(Logger::TRACE))
     {     {
         Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,          Logger::_putInternal(logFileType, systemId, Logger::TRACE,
             message, 0);              message);
     }     }
 } }
  
Line 572 
Line 458 
     _homeDirectory = homeDirectory;     _homeDirectory = homeDirectory;
 } }
  
 void Logger::setlogLevelMask( const String logLevelList )  void Logger::setlogLevelMask( const String &logLevelList )
 { {
     Uint32 logLevelType = 0;     Uint32 logLevelType = 0;
     String logLevelName      = logLevelList;     String logLevelName      = logLevelList;
Line 634 
Line 520 
     }     }
 } }
  
 Boolean Logger::isValidlogLevel(const String logLevel)  Boolean Logger::isValidlogLevel(const String &logLevel)
 { {
     // Validate the logLevel and modify the logLevel argument     // Validate the logLevel and modify the logLevel argument
     // to reflect the invalid logLevel     // to reflect the invalid logLevel
Line 674 
Line 560 
     return validlogLevel;     return validlogLevel;
 } }
  
   #if !defined (PEGASUS_USE_SYSLOGS)
   void Logger::setMaxLogFileSize(Uint32 maxLogFileSizeBytes)
   {
        LoggerRep::setMaxLogFileSize(maxLogFileSizeBytes);
   }
   #endif
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2