version 1.40.4.3, 2008/01/08 21:19:18
|
version 1.41, 2007/01/11 16:21:54
|
|
|
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Common/Thread.h> | #include <Pegasus/Common/Thread.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
#include <Pegasus/Common/HTTPMessage.h> |
|
| |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_trace( | void Tracer::_trace( |
const Uint32 traceComponent, | const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
const char* fmt, | const char* fmt, |
va_list argList) | va_list argList) |
{ | { |
|
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ |
_trace(traceComponent, "", fmt, argList); | _trace(traceComponent, "", fmt, argList); |
} | } |
|
} |
|
} |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Traces the given message - Overloaded for including FileName and Line number | //Traces the given message - Overloaded for including FileName and Line number |
|
|
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, | const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
const char* fmt, | const char* fmt, |
va_list argList) | va_list argList) |
{ | { |
char* message; | char* message; |
|
|
|
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent,traceLevel)) |
|
{ |
// | // |
// Allocate memory for the message string | // Allocate memory for the message string |
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
|
|
_trace(traceComponent, message, fmt, argList); | _trace(traceComponent, message, fmt, argList); |
delete [] message; | delete [] message; |
} | } |
|
} |
|
} |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Traces the given string - Overloaded to include the fileName and line number |
//Traces the given buffer |
//of trace origin. |
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_traceCString( |
void Tracer::_traceBuffer( |
|
const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
|
const char* data, |
|
const Uint32 size) |
|
{ |
|
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ |
|
char* tmpBuf = new char[size+1]; |
|
|
|
strncpy(tmpBuf, data, size); |
|
tmpBuf[size] = '\0'; |
|
trace(traceComponent, traceLevel, "%s", tmpBuf); |
|
|
|
delete [] tmpBuf; |
|
} |
|
} |
|
} |
|
//////////////////////////////////////////////////////////////////////////////// |
|
//Traces the given buffer - Overloaded for including FileName and Line number |
|
//////////////////////////////////////////////////////////////////////////////// |
|
void Tracer::_traceBuffer( |
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, | const Uint32 traceComponent, |
const char* cstring) |
const Uint32 traceLevel, |
|
const char* data, |
|
const Uint32 size) |
{ | { |
char* message; |
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ |
|
char* tmpBuf = new char[size+1]; |
| |
// |
strncpy( tmpBuf, data, size ); |
// Allocate memory for the message string |
tmpBuf[size] = '\0'; |
// Needs to be updated if additional info is added |
trace(fileName, lineNum, traceComponent, traceLevel, "%s", tmpBuf); |
// |
|
message = new char[strlen(fileName) + |
|
_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8]; |
|
sprintf( |
|
message, |
|
"[%d:%s:%s:%u]: ", |
|
System::getPID(), |
|
Threads::id().buffer, |
|
fileName, |
|
lineNum); |
|
| |
_traceCString(traceComponent, message, cstring); |
delete [] tmpBuf; |
delete [] message; |
} |
|
} |
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
//Traces the given string |
|
//////////////////////////////////////////////////////////////////////////////// |
|
void Tracer::_traceString( |
|
const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
|
const String& traceString) |
|
{ |
|
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent,traceLevel)) |
|
{ |
|
trace(traceComponent, traceLevel, "%s", |
|
(const char *)traceString.getCString()); |
|
} |
|
} |
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
//Traces the given string - Overloaded to include the fileName and line number |
|
//of trace origin. |
|
//////////////////////////////////////////////////////////////////////////////// |
|
void Tracer::_traceString( |
|
const char* fileName, |
|
const Uint32 lineNum, |
|
const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
|
const String& traceString) |
|
{ |
|
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ |
|
trace(fileName, lineNum, traceComponent, traceLevel, "%s", |
|
(const char *)traceString.getCString()); |
|
} |
|
} |
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_traceCIMException( | void Tracer::_traceCIMException( |
const Uint32 traceComponent, | const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
const CIMException& cimException) | const CIMException& cimException) |
{ | { |
|
if (traceLevel == LEVEL1) |
|
{ |
|
trace(traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG); |
|
} |
|
else |
|
{ |
|
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ |
// get the CIMException trace message string | // get the CIMException trace message string |
CString traceMsg = TraceableCIMException( |
String traceMsg = |
cimException).getTraceDescription().getCString(); |
TraceableCIMException(cimException).getTraceDescription(); |
|
|
// trace the string | // trace the string |
_traceCString(traceComponent, "", (const char*) traceMsg); |
_traceString(traceComponent, traceLevel, traceMsg); |
|
} |
|
} |
} | } |
| |
char* Tracer::getHTTPRequestMessage( |
//////////////////////////////////////////////////////////////////////////////// |
const Buffer& requestMessage) |
//Traces method entry |
|
//////////////////////////////////////////////////////////////////////////////// |
|
void Tracer::_traceEnter( |
|
const char* fileName, |
|
const Uint32 lineNum, |
|
const Uint32 traceComponent, |
|
const char* fmt, |
|
...) |
|
{ |
|
va_list argList; |
|
char* message; |
|
|
|
if (_isTraceEnabled(traceComponent, LEVEL1)) |
{ | { |
const Uint32 requestSize = requestMessage.size(); |
|
| |
// Make a copy of the request message. |
va_start(argList, fmt); |
AutoArrayPtr<char> requestBuf(new char [requestSize + 1]); |
|
strncpy(requestBuf.get(), requestMessage.getData(), requestSize); |
|
requestBuf.get()[requestSize] = 0; |
|
| |
// | // |
// Check if requestBuffer contains a Basic authorization header. |
// Allocate memory for the message string |
// If true, suppress the user/passwd info in the request buffer. |
// Needs to be updated if additional info is added |
// | // |
char* sep; |
message = new char[ strlen(fileName) + |
const char* line = requestBuf.get(); |
_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ]; |
| |
while ((sep = HTTPMessage::findSeparator( |
sprintf( |
line, (Uint32)(requestSize - (line - requestBuf.get())))) && |
message, |
(line != sep)) |
"[%d:%s:%s:%u]: ", |
{ |
System::getPID(), |
if (HTTPMessage::expectHeaderToken(line, "Authorization") && |
Threads::id().buffer, |
HTTPMessage::expectHeaderToken(line, ":") && |
fileName, |
HTTPMessage::expectHeaderToken(line, "Basic")) |
lineNum); |
{ |
|
// Suppress the user/passwd info |
|
HTTPMessage::skipHeaderWhitespace(line); |
|
for ( char* userpass = (char*)line ; |
|
userpass < sep; |
|
*userpass = 'X', userpass++); |
|
| |
break; |
_trace(traceComponent, message, fmt, argList); |
} |
|
| |
line = sep + ((*sep == '\r') ? 2 : 1); |
va_end(argList); |
|
delete [] message; |
} | } |
|
|
return requestBuf.release(); |
|
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Traces method entry and exit |
//Traces method exit |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_traceMethod( |
void Tracer::_traceExit( |
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, | const Uint32 traceComponent, |
const char* methodEntryExit, |
const char* fmt |
const char* method) |
...) |
{ | { |
|
va_list argList; |
char* message; | char* message; |
| |
|
if (_isTraceEnabled(traceComponent, LEVEL1)) |
|
{ |
|
va_start(argList, fmt); |
|
|
// | // |
// Allocate memory for the message string | // Allocate memory for the message string |
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
// | // |
// assume Method entry/exit string 15 characters long |
|
// +1 space character |
|
message = new char[ strlen(fileName) + | message = new char[ strlen(fileName) + |
_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 |
_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8]; |
+ 16]; |
|
| |
sprintf( | sprintf( |
message, | message, |
"[%d:%s:%s:%u]: %s ", |
"[%d:%s:%s:%u]: ", |
System::getPID(), | System::getPID(), |
Threads::id().buffer, | Threads::id().buffer, |
fileName, | fileName, |
lineNum, |
lineNum); |
methodEntryExit); |
|
| |
_traceCString(traceComponent, message, method); |
_trace(traceComponent, message, fmt, argList); |
|
va_end(argList); |
| |
delete [] message; | delete [] message; |
} | } |
|
} |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Checks if trace is enabled for the given component and level | //Checks if trace is enabled for the given component and level |
|
|
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Called by all trace interfaces with variable arguments |
//Called by all trace interfaces to log message to trace file |
//to log message to trace file |
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_trace( | void Tracer::_trace( |
const Uint32 traceComponent, | const Uint32 traceComponent, |
|
|
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
// | // |
| |
|
|
|
|
// Construct the message header | // Construct the message header |
// The message header is in the following format | // The message header is in the following format |
// timestamp: <component name> [file name:line number] | // timestamp: <component name> [file name:line number] |
|
|
else | else |
{ | { |
// | // |
// Since the message is blank, form a string using the pid and tid |
// Since the message is blank form a string using the pid and tid |
// | // |
char* tmpBuffer; | char* tmpBuffer; |
| |
|
|
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Called by all trace interfaces using a character string without format string |
|
//to log message to trace file |
|
//////////////////////////////////////////////////////////////////////////////// |
|
void Tracer::_traceCString( |
|
const Uint32 traceComponent, |
|
const char* message, |
|
const char* cstring) |
|
{ |
|
char* completeMessage; |
|
|
|
// Get the current system time and prepend to message |
|
String currentTime = System::getCurrentASCIITime(); |
|
CString timeStamp = currentTime.getCString(); |
|
// |
|
// Allocate completeMessage. |
|
// Needs to be updated if additional info is added |
|
// |
|
|
|
// Construct the message header |
|
// The message header is in the following format |
|
// timestamp: <component name> [file name:line number] |
|
if (*message != '\0') |
|
{ |
|
// << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used |
|
// in this format string |
|
completeMessage = new char [strlen(message) + |
|
strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
|
strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5 + |
|
strlen(cstring) ]; |
|
|
|
sprintf(completeMessage, "%s: %s %s%s", (const char*)timeStamp, |
|
TRACE_COMPONENT_LIST[traceComponent], message, cstring); |
|
} |
|
else |
|
{ |
|
// |
|
// Since the message is blank, form a string using the pid and tid |
|
// |
|
char* tmpBuffer; |
|
|
|
// |
|
// Allocate messageHeader. |
|
// Needs to be updated if additional info is added |
|
// |
|
tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6]; |
|
sprintf(tmpBuffer, "[%u:%s]: ", |
|
System::getPID(), Threads::id().buffer); |
|
|
|
completeMessage = new char[strlen(timeStamp) + |
|
strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
|
strlen(tmpBuffer) + 1 + 5 + |
|
strlen(cstring)]; |
|
|
|
sprintf(completeMessage, "%s: %s %s %s", (const char*)timeStamp, |
|
TRACE_COMPONENT_LIST[traceComponent], tmpBuffer, cstring); |
|
delete [] tmpBuffer; |
|
} |
|
|
|
// Call trace file handler to write message |
|
_getInstance()->_traceHandler->handleMessage(completeMessage); |
|
|
|
delete [] completeMessage; |
|
} |
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
//Validate the trace file | //Validate the trace file |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
Boolean Tracer::isValidFileName(const char* filePath) | Boolean Tracer::isValidFileName(const char* filePath) |
|
|
| |
void Tracer::traceEnter( | void Tracer::traceEnter( |
TracerToken& token, | TracerToken& token, |
|
Uint32 traceComponent, |
|
const char* method) |
|
{ |
|
if (_traceOn) |
|
{ |
|
token.component = traceComponent; |
|
token.method = method; |
|
|
|
_traceEnter( |
|
"unknown", 0, traceComponent, "%s %s", _METHOD_ENTER_MSG, method); |
|
} |
|
} |
|
|
|
void Tracer::traceExit(TracerToken& token) |
|
{ |
|
if (_traceOn) |
|
_traceExit( |
|
"unknown",0, token.component, "%s %s", |
|
_METHOD_EXIT_MSG, token.method); |
|
} |
|
|
|
void Tracer::traceEnter( |
|
TracerToken& token, |
const char* file, | const char* file, |
size_t line, | size_t line, |
Uint32 traceComponent, | Uint32 traceComponent, |
const char* method) | const char* method) |
{ | { |
|
if (_traceOn) |
|
{ |
token.component = traceComponent; | token.component = traceComponent; |
token.method = method; | token.method = method; |
| |
if (_isTraceEnabled(traceComponent, LEVEL1)) |
_traceEnter( |
{ |
file, (Uint32)line, traceComponent, "%s %s", |
_traceMethod( |
|
file, (Uint32)line, traceComponent, |
|
_METHOD_ENTER_MSG, method); | _METHOD_ENTER_MSG, method); |
} | } |
} | } |
|
|
const char* file, | const char* file, |
size_t line) | size_t line) |
{ | { |
if (_isTraceEnabled(token.component, LEVEL1) && token.method) |
if (_traceOn) |
_traceMethod( |
_traceExit( |
file, (Uint32)line, token.component, |
file, (Uint32)line, token.component, "%s %s", |
_METHOD_EXIT_MSG, token.method); | _METHOD_EXIT_MSG, token.method); |
} | } |
| |
|
void Tracer::traceBuffer( |
|
const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
|
const char* data, |
|
const Uint32 size) |
|
{ |
|
if (_traceOn) |
|
_traceBuffer(traceComponent, traceLevel, data, size); |
|
} |
|
|
|
void Tracer::traceBuffer( |
|
const char* fileName, |
|
const Uint32 lineNum, |
|
const Uint32 traceComponent, |
|
const Uint32 traceLevel, |
|
const char* data, |
|
const Uint32 size) |
|
{ |
|
if (_traceOn) |
|
{ |
|
_traceBuffer( |
|
fileName, lineNum, traceComponent, traceLevel, data, size); |
|
} |
|
} |
|
|
void Tracer::trace( | void Tracer::trace( |
const Uint32 traceComponent, | const Uint32 traceComponent, |
const Uint32 traceLevel, | const Uint32 traceLevel, |
const char *fmt, | const char *fmt, |
...) | ...) |
{ | { |
PEGASUS_ASSERT(traceLevel != LEVEL1); |
if (_traceOn) |
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ | { |
va_list argList; | va_list argList; |
|
|
va_start(argList,fmt); | va_start(argList,fmt); |
_trace(traceComponent,fmt,argList); |
_trace(traceComponent,traceLevel,fmt,argList); |
va_end(argList); | va_end(argList); |
} | } |
} | } |
|
|
const char* fmt, | const char* fmt, |
...) | ...) |
{ | { |
PEGASUS_ASSERT(traceLevel != LEVEL1); |
if (_traceOn) |
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ | { |
va_list argList; | va_list argList; |
| |
va_start(argList,fmt); | va_start(argList,fmt); |
_trace(fileName,lineNum,traceComponent,fmt,argList); |
_trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList); |
va_end(argList); | va_end(argList); |
} | } |
} | } |
| |
void Tracer::traceString( |
void Tracer::trace( |
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, | const Uint32 traceComponent, |
const Uint32 traceLevel, | const Uint32 traceLevel, |
const String& string) |
const String& traceString) |
{ | { |
PEGASUS_ASSERT(traceLevel != LEVEL1); |
if (_traceOn) |
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ | { |
_traceCString( |
_traceString( |
fileName, lineNum, traceComponent, |
fileName, lineNum, traceComponent, traceLevel, traceString); |
(const char*) string.getCString()); |
|
} | } |
} | } |
| |
void Tracer::traceCString( |
void Tracer::traceCIMException( |
const char* fileName, |
|
const Uint32 lineNum, |
|
const Uint32 traceComponent, | const Uint32 traceComponent, |
const Uint32 traceLevel, | const Uint32 traceLevel, |
const char* cstring) |
const CIMException& cimException) |
{ | { |
PEGASUS_ASSERT(traceLevel != LEVEL1); |
if (_traceOn) |
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ | { |
_traceCString( |
_traceCIMException(traceComponent, traceLevel, cimException); |
fileName, lineNum, traceComponent, cstring); |
|
} | } |
} | } |
| |
void Tracer::traceCIMException( |
void Tracer::trace( |
const Uint32 traceComponent, | const Uint32 traceComponent, |
const Uint32 traceLevel, |
const Uint32 level, |
const CIMException& cimException) |
const String& string) |
{ |
|
PEGASUS_ASSERT(traceLevel != LEVEL1); |
|
if (_isTraceEnabled(traceComponent, traceLevel)) |
|
{ | { |
_traceCIMException(traceComponent, cimException); |
trace("unknown", 0, traceComponent, level, string); |
} |
|
} | } |
| |
#endif /* !PEGASUS_REMOVE_TRACE */ | #endif /* !PEGASUS_REMOVE_TRACE */ |