(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.26 and 1.42.2.1

version 1.26, 2003/03/13 20:24:23 version 1.42.2.1, 2006/02/10 16:09:37
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // The Open Group, Tivoli Systems  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 27 
Line 35 
 //              sushma_fernandes@hp.com //              sushma_fernandes@hp.com
 // Modified By: Dave Rosckes (IBM) // Modified By: Dave Rosckes (IBM)
 //              rosckes@us.ibm.com //              rosckes@us.ibm.com
   //              Amit K Arora, IBM (amita@in.ibm.com) for PEP101
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 35 
Line 44 
 #include <cstring> #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 56 
Line 65 
     "FATAL"     "FATAL"
 }; };
  
   
 LoggerRep* Logger::_rep = 0; LoggerRep* Logger::_rep = 0;
 String Logger::_homeDirectory = "."; String Logger::_homeDirectory = ".";
  
Line 114 
Line 122 
  
     LoggerRep(const String& homeDirectory)     LoggerRep(const String& homeDirectory)
     {     {
 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)  #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 125 
Line 133 
  
         // KS: 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)){
             cerr << "Logging Disabled";             //l10n
              //cerr << "Logging Disabled";
              MessageLoaderParms parms("Common.Logger.LOGGING_DISABLED",
                  "Logging Disabled");
   
              cerr << MessageLoader::getMessage(parms);
           }
  
         CString 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);
Line 147 
Line 161 
     {     {
         int index = int(logFileType);         int index = int(logFileType);
  
         if (index > int(Logger::ERROR_LOG))          if (index > int(Logger::NUM_LOGS))
             index = Logger::ERROR_LOG;             index = Logger::ERROR_LOG;
  
         return _logs[index];         return _logs[index];
Line 164 
Line 178 
     const Uint32 logComponent, // TODO: Support logComponent mask in future release     const Uint32 logComponent, // TODO: Support logComponent mask in future release
     Uint32 logLevel,     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 197 
Line 212 
         // NUM_LEVELS = 5         // NUM_LEVELS = 5
         int sizeSvNames = sizeof(svNames) / sizeof(svNames[0]) - 1;         int sizeSvNames = sizeof(svNames) / sizeof(svNames[0]) - 1;
  
         String logMsg = Formatter::format(formatString,  // 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 != String::EMPTY)
           {
               // 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);                 arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
           }
   // l10n end
  
 #if defined(PEGASUS_USE_SYSLOGS) #if defined(PEGASUS_USE_SYSLOGS)
  
             // Open the syslog.  
             // Ignore the systemId and open the log as cimserver  
             System::openlog(systemId);  
   
             // Log the message             // Log the message
             System::syslog(logLevel,(const char*)logMsg.getCString());          System::syslog(System::CIMSERVER, logLevel, localizedMsg.getCString());
   
             // Close the syslog.  
             System::closelog();  
  
        #else        #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(": ");
             messageString.append(logMsg);          messageString.append(localizedMsg);  // l10n
  
             const char* tmp = "";             const char* tmp = "";
             if (logLevel & Logger::TRACE) tmp =       "TRACE   ";             if (logLevel & Logger::TRACE) tmp =       "TRACE   ";
Line 225 
Line 261 
             if (logLevel & Logger::WARNING) tmp =     "WARNING ";             if (logLevel & Logger::WARNING) tmp =     "WARNING ";
             if (logLevel & Logger::SEVERE) tmp =      "SEVERE  ";             if (logLevel & Logger::SEVERE) tmp =      "SEVERE  ";
             if (logLevel & Logger::FATAL) tmp =       "FATAL   ";             if (logLevel & Logger::FATAL) tmp =       "FATAL   ";
   
                 _rep->logOf(logFileType) << System::getCurrentASCIITime()                 _rep->logOf(logFileType) << System::getCurrentASCIITime()
                  << " " << tmp << messageString << endl;             << " " << tmp << (const char *)messageString.getCString() << endl;
  
        #endif        #endif
     }     }
 } }
  
   ////////////////////////////////////////////////////////////////////////////////
   //
   // Public methods start here:
   //
   ////////////////////////////////////////////////////////////////////////////////
   
   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)
   {
       if (wouldLog(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
               formatString, String::EMPTY, arg0, arg1, arg2, arg3,
               arg4, arg5, arg6, arg7, arg8, arg9);
       }
   }
   
   void Logger::put(
       LogFileType logFileType,
       const String& systemId,
       Uint32 logLevel,
       const String& formatString)
   {
       if (wouldLog(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
               formatString, String::EMPTY);
       }
   }
   
   void Logger::put(
       LogFileType logFileType,
       const String& systemId,
       Uint32 logLevel,
       const String& formatString,
       const Formatter::Arg& arg0)
   {
       if (wouldLog(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
               formatString, String::EMPTY, arg0);
       }
   }
   
   void Logger::put(
       LogFileType logFileType,
       const String& systemId,
       Uint32 logLevel,
       const String& formatString,
       const Formatter::Arg& arg0,
       const Formatter::Arg& arg1)
   {
       if (wouldLog(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
               formatString, String::EMPTY, arg0, arg1);
       }
   }
   
 void Logger::put( void Logger::put(
                  LogFileType logFileType,                  LogFileType logFileType,
                  const String& systemId,                  const String& systemId,
Line 239 
Line 348 
                  const String& formatString,                  const String& formatString,
                  const Formatter::Arg& arg0,                  const Formatter::Arg& arg0,
                  const Formatter::Arg& arg1,                  const Formatter::Arg& arg1,
       const Formatter::Arg& arg2)
   {
       if (wouldLog(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
               formatString, String::EMPTY, arg0, arg1, arg2);
       }
   }
   
   void Logger::put_l(
       LogFileType logFileType,
       const String& systemId,
       Uint32 logLevel,
       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(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
               formatString, messageId, arg0, arg1, arg2, arg3, arg4, arg5,
               arg6, arg7, arg8, arg9);
       }
   }
   
   void Logger::put_l(
        LogFileType logFileType,
        const String& systemId,
        Uint32 logLevel,
        const String& messageId,
        const String& formatString)
   {
       if (wouldLog(logLevel))
       {
           Logger::_putInternal(logFileType, systemId, 0, logLevel,
           formatString, messageId);
       }
   }
   
   void Logger::put_l(
        LogFileType logFileType,
        const String& systemId,
        Uint32 logLevel,
        const String& messageId,
        const String& 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 String& messageId,
        const String& 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 String& messageId,
        const String& 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(
       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& arg2,
                  const Formatter::Arg& arg3,                  const Formatter::Arg& arg3,
                  const Formatter::Arg& arg4,                  const Formatter::Arg& arg4,
Line 248 
Line 460 
                  const Formatter::Arg& arg8,                  const Formatter::Arg& arg8,
                  const Formatter::Arg& arg9)                  const Formatter::Arg& arg9)
 { {
     Uint32 logComponent = 0;      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);
       }
   }
  
     Logger::_putInternal(  void Logger::trace(
                         logFileType,      LogFileType logFileType,
                         systemId,      const String& systemId,
                         logComponent,      const Uint32 logComponent,
                         logLevel,      const String& formatString,
                         formatString,      const Formatter::Arg& arg0)
                         arg0,  {
                         arg1,      if (wouldLog(Logger::TRACE))
                         arg2,      {
                         arg3,          Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,
                         arg4,              formatString, String::EMPTY, arg0);
                         arg5,      }
                         arg6,  }
                         arg7,  
                         arg8,  void Logger::trace(
                         arg9);      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( void Logger::trace(
Line 275 
Line 517 
                    const String& formatString,                    const String& formatString,
                    const Formatter::Arg& arg0,                    const Formatter::Arg& arg0,
                    const Formatter::Arg& arg1,                    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& arg2,
                    const Formatter::Arg& arg3,                    const Formatter::Arg& arg3,
                    const Formatter::Arg& arg4,                    const Formatter::Arg& arg4,
Line 284 
Line 543 
                    const Formatter::Arg& arg8,                    const Formatter::Arg& arg8,
                    const Formatter::Arg& arg9)                    const Formatter::Arg& arg9)
 { {
     Uint32 logLevel = Logger::TRACE;      if (wouldLog(Logger::TRACE))
       {
           Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,
               formatString, messageId, arg0, arg1, arg2, arg3, arg4, arg5, arg6,
               arg7, arg8, arg9);
       }
   }
  
     Logger::_putInternal(  void Logger::trace_l(
                         logFileType,      LogFileType logFileType,
                         systemId,      const String& systemId,
                         logComponent,      const Uint32 logComponent,
                         logLevel,      const String& messageId,
                         formatString,      const String& formatString)
                         arg0,  {
                         arg1,      if (wouldLog(Logger::TRACE))
                         arg2,      {
                         arg3,          Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,
                         arg4,              formatString, messageId);
                         arg5,      }
                         arg6,  }
                         arg7,  
                         arg8,  void Logger::trace_l(
                         arg9);      LogFileType logFileType,
 }      const String& systemId,
       const Uint32 logComponent,
 void Logger::clean(const String& directory)      const String& messageId,
 {      const String& formatString,
     //String logFiles = logsDirectory;      const Formatter::Arg& arg0)
     //logFiles.append("/PegasusTrace.log");  {
     //cout << "Delete logs in " << logFiles << endl;      if (wouldLog(Logger::TRACE))
     //System::removeFile(logFiles.getCString());      {
     //for (i = xx; i < yy; i++)          Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE,
     //(              formatString, messageId, arg0);
     //_allocateLogFileName(directory, i)      }
     //removeFile(  }
     //}  
   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);
       }
 } }
  
 void Logger::setHomeDirectory(const String& homeDirectory) void Logger::setHomeDirectory(const String& homeDirectory)
Line 322 
Line 618 
     _homeDirectory = homeDirectory;     _homeDirectory = homeDirectory;
 } }
  
 ////////////////////////////////////////////////////////////////////////////////  
 // Set logLevel.  
 ////////////////////////////////////////////////////////////////////////////////  
 void Logger::setlogLevelMask( const String logLevelList ) void Logger::setlogLevelMask( const String logLevelList )
 { {
     Uint32 position          = 0;     Uint32 position          = 0;
     Uint32 logLevelType;      Uint32 logLevelType = 0;
     String logLevelName      = logLevelList;     String logLevelName      = logLevelList;
  
     // Check if logLevel has been specified     // Check if logLevel has been specified
Line 386 
Line 679 
     return ;     return ;
 } }
  
 Boolean Logger::isValidlogLevel(  Boolean Logger::isValidlogLevel(const String logLevel)
     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 429 
Line 721 
     return validlogLevel;     return validlogLevel;
 } }
  
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.26  
changed lines
  Added in v.1.42.2.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2