(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.9 and 1.28.6.3

version 1.9, 2001/06/05 12:52:33 version 1.28.6.3, 2003/08/14 11:55:42
Line 1 
Line 1 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
   // The Open Group, Tivoli Systems
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // copy of this software and associated documentation files (the "Software"),  // of this software and associated documentation files (the "Software"), to
 // to deal in the Software without restriction, including without limitation  // deal in the Software without restriction, including without limitation the
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // and/or sell copies of the Software, and to permit persons to whom the  // sell copies of the Software, and to permit persons to whom the Software is
 // Software is furnished to do so, subject to the following conditions:  // furnished to do so, subject to the following conditions:
 //  //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 // 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.
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By:  // Modified By: Sushma Fernandes (Hewlett-Packard Company)
   //              sushma_fernandes@hp.com
   // Modified By: Dave Rosckes (IBM)
   //              rosckes@us.ibm.com
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <iostream> #include <iostream>
 #include <fstream> #include <fstream>
 #include "System.h"  #include <cstring>
 #include "Logger.h" #include "Logger.h"
 #include "System.h" #include "System.h"
   #include "Destroyer.h"
   #include <Pegasus/Common/MessageLoader.h> //l10n
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
Line 41 
Line 48 
 const Uint32 Logger::SEVERE = (1 << 3); const Uint32 Logger::SEVERE = (1 << 3);
 const Uint32 Logger::FATAL = (1 << 4); const Uint32 Logger::FATAL = (1 << 4);
  
   static char const* LOGLEVEL_LIST[] =
   {
       "TRACE",
       "INFORMATION",
       "WARNING",
       "SEVERE",
       "FATAL"
   };
   
   
 LoggerRep* Logger::_rep = 0; LoggerRep* Logger::_rep = 0;
 String Logger::_homeDirectory = "."; String Logger::_homeDirectory = ".";
 Uint32 Logger::_severityMask = 0xFF;      // Set all on by default  
   const Uint32 Logger::_NUM_LOGLEVEL = 5;
   
   // Set separator
   const char Logger::_SEPARATOR = '@';
   
   Uint32 Logger::_severityMask;
   
 Uint32 Logger::_writeControlMask = 0xF;   // Set all on by default Uint32 Logger::_writeControlMask = 0xF;   // Set all on by default
  
   // Set the return codes
   const Boolean Logger::_SUCCESS = 1;
   const Boolean Logger::_FAILURE = 0;
   
 /* _allocLogFileName. Allocates the name from a name set. /* _allocLogFileName. Allocates the name from a name set.
     Today this is static.  However, it should be completely     Today this is static.  However, it should be completely
     configerable and driven from the config file so that     configerable and driven from the config file so that
Line 54 
Line 82 
     mask for level of severity are all driven from configuration     mask for level of severity are all driven from configuration
     input.     input.
 */ */
 static char* _allocLogFileName(  static CString _allocLogFileName(
     const String& homeDirectory,     const String& homeDirectory,
     Logger::LogFileType logFileType)     Logger::LogFileType logFileType)
 { {
     static char* fileNames[] =      static const char* fileNames[] =
     {     {
         "PegasusTrace.log",         "PegasusTrace.log",
         "PegasusStandard.log",         "PegasusStandard.log",
Line 74 
Line 102 
     const char* logFileName = fileNames[index];     const char* logFileName = fileNames[index];
  
     String result;     String result;
     result.reserve(homeDirectory.size() + 1 + strlen(logFileName));      result.reserveCapacity(homeDirectory.size() + 1 + strlen(logFileName));
     result += homeDirectory;      result.append(homeDirectory);
     result += '/';      result.append('/');
     result += logFileName;      result.append(logFileName);
     return result.allocateCString();      return result.getCString();
 } }
  
 class LoggerRep class LoggerRep
Line 87 
Line 115 
  
     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.
         char* lgDir = homeDirectory.allocateCString();          CString lgDir = homeDirectory.getCString();
  
         if (!System::isDirectory(lgDir))         if (!System::isDirectory(lgDir))
             System::makeDirectory(lgDir);             System::makeDirectory(lgDir);
  
         // I put the second test in just in case some trys to create          // KS: I put the second test in just in case some trys to create
         // a completly erronous directory.  At least we will get a message         // a completly erronous directory.  At least we will get a message
         if (!System::isDirectory(lgDir))          if (!System::isDirectory(lgDir)){
             cout << "Logging Disabled";                  //l10n
         delete [] lgDir;             //cerr << "Logging Disabled";
              MessageLoaderParms parms("Common.Logger.LOGGING_DISABLED",
                                                                   "Logging Disabled");
  
              cerr << MessageLoader::getMessage(parms);
           }
  
         char* fileName = _allocLogFileName(homeDirectory, Logger::TRACE_LOG);          CString fileName = _allocLogFileName(homeDirectory, Logger::TRACE_LOG);
         _logs[Logger::TRACE_LOG].open(fileName, ios::app);         _logs[Logger::TRACE_LOG].open(fileName, ios::app);
         delete [] fileName;  
  
         fileName = _allocLogFileName(homeDirectory, Logger::STANDARD_LOG);         fileName = _allocLogFileName(homeDirectory, Logger::STANDARD_LOG);
         _logs[Logger::STANDARD_LOG].open(fileName, ios::app);         _logs[Logger::STANDARD_LOG].open(fileName, ios::app);
         delete [] fileName;  
  
         fileName = _allocLogFileName(homeDirectory, Logger::ERROR_LOG);         fileName = _allocLogFileName(homeDirectory, Logger::ERROR_LOG);
         _logs[Logger::ERROR_LOG].open(fileName, ios::app);         _logs[Logger::ERROR_LOG].open(fileName, ios::app);
         delete [] fileName;  
  
         fileName = _allocLogFileName(homeDirectory, Logger::DEBUG_LOG);         fileName = _allocLogFileName(homeDirectory, Logger::DEBUG_LOG);
         _logs[Logger::DEBUG_LOG].open(fileName, ios::app);         _logs[Logger::DEBUG_LOG].open(fileName, ios::app);
         delete [] fileName;  #endif
  
     }     }
  
Line 135 
Line 165 
     ofstream _logs[int(Logger::NUM_LOGS)];     ofstream _logs[int(Logger::NUM_LOGS)];
 }; };
  
 void Logger::put(  void Logger::_putInternal(
     LogFileType logFileType,     LogFileType logFileType,
     const String& systemId,     const String& systemId,
     Uint32 severity,      const Uint32 logComponent, // TODO: Support logComponent mask in future release
       Uint32 logLevel,
     const String& formatString,     const String& formatString,
       const String& messageId,  // l10n
     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 151 
Line 183 
     const Formatter::Arg& arg8,     const Formatter::Arg& arg8,
     const Formatter::Arg& arg9)     const Formatter::Arg& arg9)
 { {
     // Test for severity against severity mask to determine      // Test for logLevel against severity mask to determine
     // if we write this log.     // if we write this log.
     if ((_severityMask & severity) != 0)      if ((_severityMask & logLevel) != 0)
     {     {
         if (!_rep)         if (!_rep)
            _rep = new LoggerRep(_homeDirectory);            _rep = new LoggerRep(_homeDirectory);
  
         // Get the Severity String                  // Get the logLevel String
         // This converts bitmap to string based on highest order         // This converts bitmap to string based on highest order
         // bit set         // bit set
         // ATTN: KS Fix this more efficiently.         // ATTN: KS Fix this more efficiently.
         static char* svNames[] =                  static const char* svNames[] =
             {             {
             "TRACE   ",             "TRACE   ",
             "INFO    ",             "INFO    ",
Line 173 
Line 205 
         // NUM_LEVELS = 5         // NUM_LEVELS = 5
         int sizeSvNames = sizeof(svNames) / sizeof(svNames[0]) - 1;         int sizeSvNames = sizeof(svNames) / sizeof(svNames[0]) - 1;
  
         char* tmp = "";  // l10n start
         if (severity & Logger::TRACE) tmp =       "TRACE   ";          // The localized message to be sent to the system log.
         if (severity & Logger::INFORMATION) tmp = "INFO    ";                  String localizedMsg;
         if (severity & Logger::WARNING) tmp =     "WARNING ";  
         if (severity & Logger::SEVERE) tmp =      "SEVERE  ";                  // If the caller specified a messageId, then load the localized
         if (severity & Logger::FATAL) tmp =       "FATAL   ";                  // message in the locale of the server process.
                   if (messageId != String::EMPTY)
        _rep->logOf(logFileType) << System::getCurrentASCIITime() << " " << tmp                  {
            << Formatter::format(formatString,                          // A message ID was specified.  Use the MessageLoader.
            arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) << endl;                          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
   
   #if defined(PEGASUS_USE_SYSLOGS)
   
               // Open the syslog.
               // Ignore the systemId and open the log as cimserver
               System::openlog(systemId);
   
               // Log the message
               System::syslog(logLevel,(const char*)localizedMsg.getCStringUTF8());
   
               // Close the syslog.
               System::closelog();
   
          #else
   
               // Prepend the systemId to the incoming message
               String messageString(systemId);
               messageString.append(": ");
               messageString.append(localizedMsg);  // l10n
   
               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 << messageString.getCStringUTF8() << endl;
   
          #endif
       }
   }
   
   void Logger::put(
                    LogFileType logFileType,
                    const String& systemId,
                    Uint32 logLevel,
                    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)
   {
       Uint32 logComponent = 0;
   
       Logger::_putInternal(
                           logFileType,
                           systemId,
                           logComponent,
                           logLevel,
                           formatString,
   //l10n
                           String::EMPTY,
                           arg0,
                           arg1,
                           arg2,
                           arg3,
                           arg4,
                           arg5,
                           arg6,
                           arg7,
                           arg8,
                           arg9);
   }
   
   // l10n
   void Logger::put_l(
                    LogFileType logFileType,
                    const String& systemId,
                    Uint32 logLevel,
                    const String& messageId,  // l10n
                    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)
   {
       Uint32 logComponent = 0;
  
       Logger::_putInternal(
                           logFileType,
                           systemId,
                           logComponent,
                           logLevel,
                           formatString,
                           messageId,
                           arg0,
                           arg1,
                           arg2,
                           arg3,
                           arg4,
                           arg5,
                           arg6,
                           arg7,
                           arg8,
                           arg9);
     }     }
   
   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,
                      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)
   {
       Uint32 logLevel = Logger::TRACE;
   
       Logger::_putInternal(
                           logFileType,
                           systemId,
                           logComponent,
                           logLevel,
                           formatString,
   // l10n
                           String::EMPTY,
                           arg0,
                           arg1,
                           arg2,
                           arg3,
                           arg4,
                           arg5,
                           arg6,
                           arg7,
                           arg8,
                           arg9);
 } }
  
 void Logger::clean(const String& directory)  // l10n
 {  void Logger::trace_l(
     //String logFiles = logsDirectory;                     LogFileType logFileType,
     //logFiles.append("/PegasusTrace.log");                     const String& systemId,
     //char* lgFiles = logFiles.allocateCString();                     const Uint32 logComponent,
     //cout << "Delete logs in " << logFiles << endl;                     const String& messageId,
     //System::removeFile(lgFiles);                     const String& formatString,
     //delete [] lgFiles;                     const Formatter::Arg& arg0,
     //for (i = xx; i < yy; i++)                     const Formatter::Arg& arg1,
     //(                     const Formatter::Arg& arg2,
     //_allocateLogFileName(directory, i)                     const Formatter::Arg& arg3,
     //removeFile(                     const Formatter::Arg& arg4,
     //}                     const Formatter::Arg& arg5,
                      const Formatter::Arg& arg6,
                      const Formatter::Arg& arg7,
                      const Formatter::Arg& arg8,
                      const Formatter::Arg& arg9)
   {
       Uint32 logLevel = Logger::TRACE;
   
       Logger::_putInternal(
                           logFileType,
                           systemId,
                           logComponent,
                           logLevel,
                           formatString,
                           messageId,
                           arg0,
                           arg1,
                           arg2,
                           arg3,
                           arg4,
                           arg5,
                           arg6,
                           arg7,
                           arg8,
                           arg9);
 } }
  
 void Logger::setHomeDirectory(const String& homeDirectory) void Logger::setHomeDirectory(const String& homeDirectory)
Line 207 
Line 427 
     _homeDirectory = homeDirectory;     _homeDirectory = homeDirectory;
 } }
  
   ////////////////////////////////////////////////////////////////////////////////
   // Set logLevel.
   ////////////////////////////////////////////////////////////////////////////////
   void Logger::setlogLevelMask( const String logLevelList )
   {
       Uint32 position          = 0;
       Uint32 logLevelType;
       String logLevelName      = logLevelList;
   
       // Check if logLevel has been specified
       if (logLevelName != String::EMPTY)
       {
           // initialise _severityMask
           _severityMask = 0;
   
           // Set logLevelType to indicate the level of logging
           // required by the user.
           if (String::equalNoCase(logLevelName,"TRACE"))
           {
               logLevelType =  Logger::TRACE;
           }
           else if (String::equalNoCase(logLevelName,"INFORMATION"))
           {
               logLevelType =  Logger::INFORMATION;
           }
           else if (String::equalNoCase(logLevelName,"WARNING"))
           {
               logLevelType = Logger::WARNING;
           }
           else if (String::equalNoCase(logLevelName,"SEVERE"))
           {
               logLevelType = Logger::SEVERE;
           }
           else if (String::equalNoCase(logLevelName,"FATAL"))
           {
               logLevelType = Logger::FATAL;
           }
           // Setting _severityMask.  NOTE:  When adding new logLevels
           // it is essential that they are adding in ascending order
           // based on priority.  Once a case statement is true we will
           // continue to set all following log levels with a higher
           // priority.
           switch(logLevelType)
           {
               case Logger::TRACE:
                     _severityMask |= Logger::TRACE;
               case Logger::INFORMATION:
                     _severityMask |= Logger::INFORMATION;
               case Logger::WARNING:
                     _severityMask |= Logger::WARNING;
               case Logger::SEVERE:
                     _severityMask |= Logger::SEVERE;
               case Logger::FATAL:
                     _severityMask |= Logger::FATAL;
           }
       }
       else
       {
           // Property logLevel not specified, set default value.
           _severityMask = ~Logger::TRACE;
       }
       return ;
   }
   
   Boolean Logger::isValidlogLevel(
       const String logLevel)
   {
       // Validate the logLevel and modify the logLevel argument
       // to reflect the invalid logLevel
   
       Uint32    position=0;
       Uint32    index=0;
       String    logLevelName = String::EMPTY;
       Boolean   validlogLevel=false;
       Boolean   retCode=true;
   
       logLevelName = logLevel;
   
       if (logLevelName != String::EMPTY)
       {
           // Lookup the index for logLevel name in _logLevel_LIST
           index = 0;
           validlogLevel = false;
   
           while (index < _NUM_LOGLEVEL)
           {
               if (String::equalNoCase(logLevelName, LOGLEVEL_LIST[index]))
               {
                   // Found logLevel, break from the loop
                   validlogLevel = true;
                   break;
               }
               else
               {
                   index++;
               }
           }
       }
       else
       {
           // logLevels is empty, it is a valid value so return true
           return _SUCCESS;
       }
   
       return validlogLevel;
   }
   
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.9  
changed lines
  Added in v.1.28.6.3

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2