(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.54 and 1.55

version 1.54, 2007/06/15 17:40:07 version 1.55, 2007/09/04 05:27:26
Line 34 
Line 34 
 #include <iostream> #include <iostream>
 #include <fstream> #include <fstream>
 #include <cstring> #include <cstring>
 #include "Logger.h"  #include <Pegasus/Common/Logger.h>
 #include "System.h"  #include <Pegasus/Common/System.h>
   #include <Pegasus/Common/FileSystem.h>
 #include <Pegasus/Common/MessageLoader.h> #include <Pegasus/Common/MessageLoader.h>
 #include <Pegasus/Common/Executor.h> #include <Pegasus/Common/Executor.h>
   #include <Pegasus/Common/Mutex.h>
  
 #if defined(PEGASUS_USE_SYSLOGS) #if defined(PEGASUS_USE_SYSLOGS)
 # include <syslog.h> # include <syslog.h>
Line 47 
Line 49 
  
 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);
 const Uint32 Logger::WARNING = (1 << 2); const Uint32 Logger::WARNING = (1 << 2);
Line 78 
Line 83 
 const Boolean Logger::_SUCCESS = 1; const Boolean Logger::_SUCCESS = 1;
 const Boolean Logger::_FAILURE = 0; const Boolean Logger::_FAILURE = 0;
  
 /* _allocLogFileName. Allocates the name from a name set.  
     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 _allocLogFileName(  
     const String& homeDirectory,  
     Logger::LogFileType logFileType)  
 {  
     static const char* fileNames[] =     static const char* fileNames[] =
     {     {
         "PegasusTrace.log",         "PegasusTrace.log",
Line 98 
Line 91 
         "PegasusError.log",         "PegasusError.log",
         "PegasusDebug.log"         "PegasusDebug.log"
     };     };
   static const char* lockFileName =  "PegasusLog.lock";
  
     int index = int(logFileType);  
   
     if (index >= Logger::NUM_LOGS)  
         index = Logger::ERROR_LOG;  
  
     const char* logFileName = fileNames[index];  /* _constructFileName prepares the absolute file name from homeDirectory
       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(
       const String& homeDirectory,
       const char * fileName)
   {
     String result;     String result;
     result.reserveCapacity((Uint32)(homeDirectory.size() + 1 +     result.reserveCapacity((Uint32)(homeDirectory.size() + 1 +
         strlen(logFileName)));          strlen(fileName)));
     result.append(homeDirectory);     result.append(homeDirectory);
     result.append('/');     result.append('/');
     result.append(logFileName);      result.append(fileName);
     return result.getCString();     return result.getCString();
 } }
  
Line 140 
Line 142 
             cerr << MessageLoader::getMessage(parms);             cerr << MessageLoader::getMessage(parms);
         }         }
  
         CString fileName = _allocLogFileName(homeDirectory, Logger::TRACE_LOG);         //Filelocks are not used for VMS
         _logs[Logger::TRACE_LOG].open(fileName, ios::app);  #if !defined(PEGASUS_OS_VMS)
           _loggerLockFileName = _constructFileName(homeDirectory, lockFileName);
   
           // Open and close a file to make sure that the file exists, on which
           // file lock is requested
           FILE *fileLockFilePointer;
           fileLockFilePointer = fopen(_loggerLockFileName, "a+");
           if(fileLockFilePointer)
           {
               fclose(fileLockFilePointer);
           }
   #endif
   
  
         fileName = _allocLogFileName(homeDirectory, Logger::STANDARD_LOG);          _logFileNames[Logger::TRACE_LOG] = _constructFileName(homeDirectory,
         _logs[Logger::STANDARD_LOG].open(fileName, ios::app);                                                 fileNames[Logger::TRACE_LOG]);
   
           _logFileNames[Logger::STANDARD_LOG] = _constructFileName(homeDirectory,
                                                  fileNames[Logger::STANDARD_LOG]);
  
 #ifndef PEGASUS_DISABLE_AUDIT_LOGGER #ifndef PEGASUS_DISABLE_AUDIT_LOGGER
         fileName = _allocLogFileName(homeDirectory, Logger::AUDIT_LOG);          _logFileNames[Logger::AUDIT_LOG] = _constructFileName(homeDirectory,
         _logs[Logger::AUDIT_LOG].open(fileName, ios::app);                                                 fileNames[Logger::AUDIT_LOG]);
 #endif #endif
  
         fileName = _allocLogFileName(homeDirectory, Logger::ERROR_LOG);          _logFileNames[Logger::ERROR_LOG] = _constructFileName(homeDirectory,
         _logs[Logger::ERROR_LOG].open(fileName, ios::app);                                                 fileNames[Logger::ERROR_LOG]);
  
         fileName = _allocLogFileName(homeDirectory, Logger::DEBUG_LOG);          _logFileNames[Logger::DEBUG_LOG] = _constructFileName(homeDirectory,
         _logs[Logger::DEBUG_LOG].open(fileName, ios::app);                                                 fileNames[Logger::DEBUG_LOG]);
 #else #else
  
 #ifdef PEGASUS_OS_ZOS #ifdef PEGASUS_OS_ZOS
Line 170 
Line 187 
  
     ~LoggerRep()     ~LoggerRep()
     {     {
 #if !defined(PEGASUS_USE_SYSLOGS)  
         _logs[Logger::TRACE_LOG].close();  
         _logs[Logger::STANDARD_LOG].close();  
  
 #ifndef PEGASUS_DISABLE_AUDIT_LOGGER  #ifdef PEGASUS_OS_ZOS
         _logs[Logger::AUDIT_LOG].close();          System::closelog();
           free(logIdentity);
 #endif #endif
       }
  
         _logs[Logger::ERROR_LOG].close();      // Actual logging is done in this routine
         _logs[Logger::DEBUG_LOG].close();      void log(Logger::LogFileType logFileType,
           const String& systemId,
           Uint32 logLevel,
           const String localizedMsg)
       {
   #if defined(PEGASUS_USE_SYSLOGS)
   
           // Log the message
           System::syslog(systemId, logLevel, localizedMsg.getCString());
  
 #else #else
           // Prepend the systemId to the incoming message
           String messageString(systemId);
           messageString.append(": ");
           messageString.append(localizedMsg);  // l10n
  
 #ifdef PEGASUS_OS_ZOS          // Get the logLevel String
         System::closelog();          // This converts bitmap to string based on highest order
         free(logIdentity);          // bit set
 #endif          // ATTN: KS Fix this more efficiently.
           const char* tmp = "";
           if (logLevel & Logger::TRACE) tmp =       "TRACE   ";
           if (logLevel & Logger::INFORMATION) tmp = "INFO    ";
           if (logLevel & Logger::WARNING) tmp =     "WARNING ";
           if (logLevel & Logger::SEVERE) tmp =      "SEVERE  ";
           if (logLevel & Logger::FATAL) tmp =       "FATAL   ";
  
 #endif  # ifndef PEGASUS_OS_VMS
           // Acquire AutoMutex (for thread sync)
           // and AutoFileLock (for Process Sync).
           AutoMutex am(_mutex);
           AutoFileLock fileLock(_loggerLockFileName);
  
     }          Uint32  logFileSize = 0;
   
           // Read logFileSize to check if the logfile needs to be pruned.
           FileSystem::getFileSize(String(_logFileNames[logFileType]),
                                          logFileSize);
  
     ostream& logOf(Logger::LogFileType logFileType)          // Check if the size of the logfile is exceeding 32MB.
           if ( logFileSize > PEGASUS_MAX_LOGFILE_SIZE)
     {     {
         int index = int(logFileType);              // Prepare appropriate file name based on the logFileType.
               // Eg: if Logfile name is PegasusStandard.log, pruned logfile name
               // will be PegasusStandard-062607-122302.log,where 062607-122302
               // is the time stamp.
               String prunedLogfile(_logFileNames[logFileType],
                                   (Uint32)strlen(_logFileNames[logFileType]) - 4);
               prunedLogfile.append('-');
  
         if (index > int(Logger::NUM_LOGS))              // Get timestamp,remove illegal chars in file name'/' and ':'
             index = Logger::ERROR_LOG;              // (: is illegal Open VMS) from the time stamp. Append the time
               // info to the file name.
  
         return _logs[index];              String timeStamp = System::getCurrentASCIITime();
               for (unsigned int i=0; i<=timeStamp.size(); i++)
               {
                   if(timeStamp[i] == '/' || timeStamp[i] == ':')
                   {
                       timeStamp.remove(i, 1);
                   }
               }
               prunedLogfile.append(timeStamp);
   
               // Append '.log' to the file
               prunedLogfile.append( ".log");
   
               // Rename the logfile
               FileSystem::renameFile(String(_logFileNames[logFileType]),
                                      prunedLogfile);
   
           } // Check if the logfile needs to be pruned.
   # endif  // ifndef PEGASUS_OS_VMS
   
           // Open Logfile. Based on the value of logFileType, one of the five
           // Logfiles will be opened.
           ofstream logFileStream;
           logFileStream.open(_logFileNames[logFileType], ios::app);
           logFileStream << System::getCurrentASCIITime()
              << " " << tmp << (const char *)messageString.getCString() << endl;
           logFileStream.close();
   #endif // ifndef PEGASUS_USE_SYSLOGS
     }     }
  
 private: private:
Line 207 
Line 284 
 #ifdef PEGASUS_OS_ZOS #ifdef PEGASUS_OS_ZOS
     char* logIdentity;     char* logIdentity;
 #endif #endif
     ofstream _logs[int(Logger::NUM_LOGS)];      CString _logFileNames[int(Logger::NUM_LOGS)];
   #ifndef PEGASUS_OS_VMS
       CString _loggerLockFileName;
       Mutex _mutex;
   #endif
 }; };
  
 void Logger::_putInternal( void Logger::_putInternal(
Line 267 
Line 348 
         }         }
 // l10n end // l10n end
  
 #if defined(PEGASUS_USE_SYSLOGS)  
  
         // Log the message         // Call the actual logging routine is in LoggerRep.
         System::syslog(systemId, logLevel, localizedMsg.getCString());         _rep->log(logFileType, systemId, logLevel, localizedMsg);
   
 #else  
   
         // Prepend the systemId to the incoming message  
         String messageString(systemId);  
         messageString.append(": ");  
         messageString.append(localizedMsg);  // l10n  
   
         // Get the logLevel String  
         // This converts bitmap to string based on highest order  
         // bit set  
         // ATTN: KS Fix this more efficiently.  
         const char* tmp = "";  
         if (logLevel & Logger::TRACE) tmp =       "TRACE   ";  
         if (logLevel & Logger::INFORMATION) tmp = "INFO    ";  
         if (logLevel & Logger::WARNING) tmp =     "WARNING ";  
         if (logLevel & Logger::SEVERE) tmp =      "SEVERE  ";  
         if (logLevel & Logger::FATAL) tmp =       "FATAL   ";  
   
         _rep->logOf(logFileType) << System::getCurrentASCIITime()  
            << " " << tmp << (const char *)messageString.getCString() << endl;  
   
 #endif  
     }     }
 } }
  


Legend:
Removed from v.1.54  
changed lines
  Added in v.1.55

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2