version 1.62, 2008/08/12 18:26:27
|
version 1.67, 2008/12/02 09:00:48
|
|
|
//%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. |
|
// | // |
//============================================================================== |
////////////////////////////////////////////////////////////////////////// |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
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); |
|
|
| |
Uint32 Logger::_severityMask; | Uint32 Logger::_severityMask; |
| |
|
|
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// |
// | // |
// LoggerRep | // LoggerRep |
|
|
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 |
|
|
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) |
| |
| |
|
|
const String& systemId, | const String& systemId, |
const Uint32 logComponent, // FUTURE: Support logComponent mask | 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()); |
} |
|
} | } |
} | } |
} | } |
|
|
if (wouldLog(logLevel)) | if (wouldLog(logLevel)) |
{ | { |
Logger::_putInternal(logFileType, systemId, 0, logLevel, | Logger::_putInternal(logFileType, systemId, 0, 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)); |
} | } |
} | } |
| |
|
|
{ | { |
if (wouldLog(logLevel)) | if (wouldLog(logLevel)) |
{ | { |
Logger::_putInternal(logFileType, systemId, 0, logLevel, |
Logger::_putInternal(logFileType, systemId, 0, logLevel, formatString); |
formatString, 0); |
|
} | } |
} | } |
| |
|
|
if (wouldLog(logLevel)) | if (wouldLog(logLevel)) |
{ | { |
Logger::_putInternal(logFileType, systemId, 0, logLevel, | Logger::_putInternal(logFileType, systemId, 0, logLevel, |
formatString, 0, arg0); |
Formatter::format(formatString, arg0)); |
} | } |
} | } |
| |
|
|
if (wouldLog(logLevel)) | if (wouldLog(logLevel)) |
{ | { |
Logger::_putInternal(logFileType, systemId, 0, logLevel, | Logger::_putInternal(logFileType, systemId, 0, logLevel, |
formatString, 0, arg0, arg1); |
Formatter::format(formatString, arg0, arg1)); |
} | } |
} | } |
| |
|
|
if (wouldLog(logLevel)) | if (wouldLog(logLevel)) |
{ | { |
Logger::_putInternal(logFileType, systemId, 0, logLevel, | Logger::_putInternal(logFileType, systemId, 0, logLevel, |
formatString, 0, arg0, arg1, arg2); |
Formatter::format(formatString, arg0, arg1, arg2)); |
} | } |
} | } |
| |
|
|
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)) |
{ | { |
|
MessageLoaderParms parms = msgParms; |
|
parms.useProcessLocale = true; |
Logger::_putInternal(logFileType, systemId, 0, logLevel, | Logger::_putInternal(logFileType, systemId, 0, logLevel, |
formatString, messageId, arg0, arg1, arg2, arg3, arg4, arg5, |
MessageLoader::getMessage(parms)); |
arg6, arg7, arg8, arg9); |
|
} |
|
} |
|
|
|
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); |
|
} | } |
} | } |
| |
|
|
if (wouldLog(Logger::TRACE)) | if (wouldLog(Logger::TRACE)) |
{ | { |
Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE, | Logger::_putInternal(logFileType, systemId, logComponent, Logger::TRACE, |
message, 0); |
message); |
} | } |
} | } |
| |
|
|
return validlogLevel; | return validlogLevel; |
} | } |
| |
|
#if !defined (PEGASUS_USE_SYSLOGS) |
|
void Logger::setMaxLogFileSize(Uint32 maxLogFileSizeBytes) |
|
{ |
|
LoggerRep::setMaxLogFileSize(maxLogFileSizeBytes); |
|
} |
|
#endif |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |