version 1.55.2.4, 2007/11/05 01:47:23
|
version 1.58, 2008/05/07 19:41:42
|
|
|
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
// Log callback function and data. |
|
static Logger::LogCallback _callback; |
|
static void* _data; |
|
|
|
// Maximum logfile size is defined as 32 MB = 32 * 1024 * 1024 | // Maximum logfile size is defined as 32 MB = 32 * 1024 * 1024 |
# define PEGASUS_MAX_LOGFILE_SIZE 0X2000000 | # define PEGASUS_MAX_LOGFILE_SIZE 0X2000000 |
| |
|
|
| |
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) |
|
|
|
class LoggerRep |
|
{ |
|
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 |
|
}; |
| |
// Set the return codes |
#else // !defined(PEGASUS_USE_SYSLOGS) |
const Boolean Logger::_SUCCESS = 1; |
|
const Boolean Logger::_FAILURE = 0; |
|
| |
static const char* fileNames[] = | static const char* fileNames[] = |
{ | { |
|
|
}; | }; |
static const char* lockFileName = "PegasusLog.lock"; | static const char* lockFileName = "PegasusLog.lock"; |
| |
#if defined(PEGASUS_OS_VXWORKS) && defined(log) |
/* |
# undef log |
_constructFileName builds the absolute file name from homeDirectory |
#endif |
|
|
|
/* _constructFileName prepares 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); |
|
|
| |
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. |
|
|
} | } |
#endif | #endif |
| |
|
|
_logFileNames[Logger::TRACE_LOG] = _constructFileName(homeDirectory, | _logFileNames[Logger::TRACE_LOG] = _constructFileName(homeDirectory, |
fileNames[Logger::TRACE_LOG]); | fileNames[Logger::TRACE_LOG]); |
| |
_logFileNames[Logger::STANDARD_LOG] = _constructFileName(homeDirectory, | _logFileNames[Logger::STANDARD_LOG] = _constructFileName(homeDirectory, |
fileNames[Logger::STANDARD_LOG]); | fileNames[Logger::STANDARD_LOG]); |
| |
#ifndef PEGASUS_DISABLE_AUDIT_LOGGER |
# ifdef PEGASUS_ENABLE_AUDIT_LOGGER |
_logFileNames[Logger::AUDIT_LOG] = _constructFileName(homeDirectory, | _logFileNames[Logger::AUDIT_LOG] = _constructFileName(homeDirectory, |
fileNames[Logger::AUDIT_LOG]); | fileNames[Logger::AUDIT_LOG]); |
#endif | #endif |
| |
_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 |
|
|
Uint32 logLevel, | Uint32 logLevel, |
const String localizedMsg) | const String localizedMsg) |
{ | { |
// Use logging callback if installed and bypass logging logic below. |
|
|
|
if (_callback) |
|
{ |
|
// Set type: |
|
|
|
int type; |
|
|
|
switch (logFileType) |
|
{ |
|
case Logger::TRACE_LOG: |
|
type = 1; |
|
break; |
|
case Logger::STANDARD_LOG: |
|
type = 2; |
|
break; |
|
case Logger::AUDIT_LOG: |
|
type = 3; |
|
break; |
|
case Logger::ERROR_LOG: |
|
type = 4; |
|
break; |
|
case Logger::DEBUG_LOG: |
|
type = 5; |
|
break; |
|
default: |
|
return; |
|
} |
|
|
|
// Set system: |
|
|
|
CString system(systemId.getCString()); |
|
|
|
// Set level: |
|
|
|
int level; |
|
|
|
switch (logLevel) |
|
{ |
|
case Logger::TRACE: |
|
level = 1; |
|
break; |
|
case Logger::INFORMATION: |
|
level = 2; |
|
break; |
|
case Logger::WARNING: |
|
level = 3; |
|
break; |
|
case Logger::SEVERE: |
|
level = 4; |
|
break; |
|
case Logger::FATAL: |
|
level = 5; |
|
break; |
|
default: |
|
return; |
|
} |
|
|
|
// Set message: |
|
|
|
CString message(localizedMsg.getCString()); |
|
|
|
// Invoke the callback. |
|
|
|
(*_callback)(type, system, level, message, _data); |
|
|
|
return; |
|
} |
|
|
|
#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(": "); |
|
|
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, |
|
|
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; |
} | } |
| |
|
|
void Logger::setLogCallback(Logger::LogCallback callback, void* data) |
|
{ |
|
_callback = callback; |
|
_data = data; |
|
} |
|
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |