You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by wh...@apache.org on 2005/02/03 10:56:00 UTC
cvs commit: ws-axis/c/src/common AxisTrace.cpp AxisTrace.h
whitlock 2005/02/03 01:55:59
Modified: c/src/common AxisTrace.cpp AxisTrace.h
Log:
Change trace format to support free trace viewer available from http://alphaworks.ibm.com/tech/ta4was
Revision Changes Path
1.55 +114 -155 ws-axis/c/src/common/AxisTrace.cpp
Index: AxisTrace.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/common/AxisTrace.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- AxisTrace.cpp 18 Jan 2005 15:02:20 -0000 1.54
+++ AxisTrace.cpp 3 Feb 2005 09:55:59 -0000 1.55
@@ -31,6 +31,8 @@
// cctype is needed to make isprint compile on linux
#include <cctype>
#include <exception>
+#include <ctime>
+#include <cstring>
extern AXIS_CPP_NAMESPACE_PREFIX AxisConfig* g_pConfig;
AXIS_CPP_NAMESPACE_START
@@ -38,7 +40,6 @@
bool AxisTrace::m_bLoggingOn = false;
AxisFile *AxisTrace::m_fileTrace = NULL;
-std::stack<std::string> AxisTrace::m_stack;
int AxisTrace::openFile ()
{
@@ -78,71 +79,24 @@
return m_bLoggingOn;
}
-int AxisTrace::logaxis (const char* sLog1, const char* sLog2, int level,
- char* arg3, int arg4)
+int AxisTrace::logaxis (const char* sLog1, const char* sLog2, const char *type,
+ char* file, int line)
{
if (!m_bLoggingOn) return AXIS_FAIL;
- time_t ltime;
- time (<ime);
- string text = "Severity Level : ";
- switch (level)
- {
- case 1:
- text += "CRITICAL";
- break;
- case 2:
- text += "WARN";
- break;
- case 3:
- text += "INFO";
- break;
- default:
- text += "TRIVIAL";
- break;
- }
+ string name = file;
+ name += "@";
+ name += line;
- traceLine(text.c_str());
- text = "time : ";
- text += ctime (<ime);
- text += "file : ";
- text += arg3;
- traceLine(text.c_str());
- text = "line : ";
- char buff[32];
- sprintf (buff, "%d", arg4);
- text += buff;
- traceLine(text.c_str());
- text = sLog1;
+ string text = sLog1;
text += ":";
if(0 != sLog2)
text += sLog2;
- traceLine(text.c_str());
- traceLine("-------------------------------------------------");
- return AXIS_SUCCESS;
-}
-int AxisTrace::logaxis (const char* sLog, int level, char* arg2, int arg3)
-{
- return logaxis(sLog,NULL,level,arg2,arg3);
-}
-/*
-int AxisTrace::logaxis (const char* sLog1, const int nLog2, int level,
- char* arg3, int arg4)
-{
- char convToInt[32];
- sprintf(convToInt, "%d", nLog2);
- return logaxis(sLog1,convToInt,level,arg3,arg4);
+ traceLineInternal(type,name.c_str(),NULL,NULL,text.c_str());
+ return AXIS_SUCCESS;
}
-int AxisTrace::logaxis (const char* sLog1, const double dLog2, int level,
- char* arg3, int arg4)
-{
- char convToDouble[32];
- sprintf(convToDouble, "%f", dLog2);
- return logaxis(sLog1,convToDouble,level,arg3,arg4);
-}
-*/
int AxisTrace::trace (const char *pchLog)
{
if (pchLog != NULL) {
@@ -154,20 +108,19 @@
void AxisTrace::traceHeader()
{
- traceLine("--------- Axis C++ trace ----------");
+ traceLine2("************ Start Display Current Environment ************");
string text = "Axis C++ libraries built on ";
text += __DATE__;
text += " at ";
text += __TIME__;
- traceLine(text.c_str());
+ traceLine2(text.c_str());
time_t ltime;
time (<ime);
text = "Trace produced on ";
text += ctime (<ime);
- traceLine(text.c_str());
+ traceLine2(text.c_str());
- traceLine("Dumping environment variables...");
char *envVars[]={"PATH","LIBPATH","LD_LIBRARY_PATH","AXISCPP_DEPLOY","PWD",
"CLASSPATH","INCLUDE","LIB","NLSPATH","OS","COMPUTERNAME","USERNAME",
"HOSTNAME","LANG","LOGIN","LOGNAME","MACHTYPE","OSTYPE","UID","USER"};
@@ -175,17 +128,14 @@
{
text = envVars[i];
const char *value = getenv(envVars[i]);
- if (NULL==value)
- {
- text += " was not set";
- }
- else
+ if (NULL!=value)
{
text += "=";
text += value;
+ traceLine2(text.c_str());
}
- traceLine(text.c_str());
}
+ traceLine2("************* End Display Current Environment *************");
// Write out the config settings
traceLine("-------------- Config File settings START ----------------");
@@ -235,8 +185,65 @@
}
+void AxisTrace::traceLineInternal(const char *type, const char *classname,
+ const char *methodname, const void *that,
+ const char *parms)
+{
+ time_t current = time(NULL);
+ struct tm *tm = localtime(¤t);
+
+ // TODO: Milliseconds
+ const int timelen=256;
+ char strtime[timelen];
+ memset(strtime,0,timelen);
+ strftime(strtime,timelen,"[%d/%m/%y %H:%M:%S:000 %Z]",tm);
+ strtime[timelen-1]='\0';
+
+ string text = strtime;
+ text += " 1 "; // TODO: this should be the thread id
+
+ if (NULL==classname) text += "-";
+ else text += classname;
+ text += " ";
+ text += type;
+ if (NULL!=methodname) {
+ text += " ";
+ text += methodname;
+ }
+ text += " ";
+ if (NULL != that) {
+ char prim[32];
+ sprintf(prim,"|%p|",that);
+ text += prim;
+ if (NULL!=parms) text += ",";
+ }
+
+ if (NULL != parms) {
+ if (NULL==strchr(parms,'\n')) {
+ text += parms;
+ traceLine2(text.c_str());
+ } else {
+ // Multi-line output
+ text += "------------>";
+ traceLine2(text.c_str());
+ const char *tok = strtok(const_cast<char*>(parms),"\n");
+ while (NULL != tok) {
+ traceLineInternal(tok);
+ tok = strtok(NULL,"\n");
+ }
+ }
+ } else {
+ traceLine2(text.c_str());
+ }
+}
+
void AxisTrace::traceLineInternal(const char *data)
{
+ traceLineInternal(TRACE_INFO,NULL,NULL,NULL,data);
+}
+
+void AxisTrace::traceLine2(const char *data)
+{
if (!isTraceOn()) return;
m_fileTrace->filePuts(data);
m_fileTrace->filePuts("\n");
@@ -251,44 +258,22 @@
try {
string line;
- for (unsigned is=0; is<m_stack.size(); is++) line += " ";
- line += "{ ";
- if (NULL!=className) {
- line += className;
- line += "::";
+ const char *parms = NULL;
+ if (0<nParms) {
+ for (int i=0; i<nParms; i++) {
+ int type = va_arg(args, int);
+ unsigned len = va_arg(args, unsigned);
+ void *value = va_arg(args, void*);
+ if (0!=i) line += ", ";
+ addParameter(line,type,len,value);
+ }
+ parms = line.c_str();
}
- if (NULL!=methodName)
- line += methodName;
- if (NULL!=that) {
- line += "<";
- char prim[32];
- sprintf(prim,"%p",that);
- line += prim;
- line += ">";
- }
- line += "(";
- for (int i=0; i<nParms; i++) {
- int type = va_arg(args, int);
- unsigned len = va_arg(args, unsigned);
- void *value = va_arg(args, void*);
- if (0!=i) line += ", ";
- addParameter(line,type,len,value);
- }
-
- line += ")";
- traceLine(line.c_str());
+ traceLineInternal(TRACE_ENTRY,className,methodName,that,parms);
} catch (...) {
- traceLine("Unknown exception caught during trace entry");
+ traceLineInternal(TRACE_EXCEPT,NULL,NULL,NULL,"Unknown exception caught during trace entry");
}
-
- string name;
- if (NULL!=className) {
- name = className;
- name += "::";
- name += methodName;
- } else name = methodName;
- m_stack.push(name);
}
void AxisTrace::traceExitInternal(const char *className, const char *methodName, int returnIndex,
@@ -297,38 +282,25 @@
if (!isTraceOn()) return;
try {
- // Careful here in case entries and exits don't match
- string name;
- if (NULL!=className) {
- name = className;
- name += "::";
- name += methodName;
- } else name = methodName;
- while (m_stack.size()>0 && name!=m_stack.top()) m_stack.pop();
- if (m_stack.size()>0) m_stack.pop();
-
string line;
- for (unsigned is=0; is<m_stack.size(); is++) line += " ";
- line += "} ";
- if (NULL!=className) {
- line += className;
- line += "::";
- }
- if (NULL!=methodName)
- line += methodName;
- if (0!=returnIndex) { // Zero means only one return
- line += "@";
- char prim[32];
- sprintf(prim,"%d",returnIndex);
- line += prim;
- }
- line += "(";
- if (TRACETYPE_UNKNOWN != type)
+ bool added = false;
+ if (0!=returnIndex) { // Zero means only one return
+ line = "@";
+ char prim[32];
+ sprintf(prim,"%d",returnIndex);
+ line += prim;
+ added = true;
+ }
+
+ if (TRACETYPE_UNKNOWN != type) {
+ if (added) line += " ";
addParameter(line,type,len,value);
- line += ")";
- traceLine(line.c_str());
+ added = true;
+ }
+
+ traceLineInternal(TRACE_EXIT,className,methodName,NULL,added?line.c_str():NULL);
} catch (...) {
- traceLine("Unknown exception caught during trace exit");
+ traceLineInternal(TRACE_EXCEPT,NULL,NULL,NULL,"Unknown exception caught during trace exit");
}
}
@@ -338,35 +310,22 @@
if (!isTraceOn()) return;
try {
- // The method that caught the exception may not be top of the stack.
- string name = className;
- name += "::";
- name += methodName;
- while (m_stack.size()>0 && name!=m_stack.top()) m_stack.pop();
-
string line;
- for (unsigned is=0; is<m_stack.size(); is++) line += " ";
- line += "! ";
- if (NULL!=className) {
- line += className;
- line += "::";
- }
- if (NULL!=methodName)
- line += methodName;
- line += " caught ";
- if (0!=catchIndex) { // Zero means only one catch
- line += "@";
- char prim[32];
- sprintf(prim,"%d",catchIndex);
- line += prim;
- line += " ";
- }
+ if (0!=catchIndex) { // Zero means only one catch
+ line = "@";
+ char prim[32];
+ sprintf(prim,"%d",catchIndex);
+ line += prim;
+ line += " ";
+ }
+
+ line += "caught ";
if (TRACETYPE_UNKNOWN != type)
addParameter(line,type,len,value);
- else line += "\"...\"";
- traceLine(line.c_str());
+ else line += "\"...\"";
+ traceLineInternal(TRACE_EXCEPT,className,methodName,NULL,line.c_str());
} catch (...) {
- traceLine("Unknown exception caught during trace catch");
+ traceLineInternal(TRACE_EXCEPT,NULL,NULL,NULL,"Unknown exception caught during trace catch");
}
}
@@ -380,7 +339,7 @@
case TRACETYPE_USHORT: sprintf(prim,"%hu",*((short *)value)); line += prim; break;
case TRACETYPE_SHORT: sprintf(prim,"%hd",*((short *)value)); line += prim; break;
case TRACETYPE_UINT: sprintf(prim,"%u" ,*((int *)value)); line += prim; break;
- case TRACETYPE_INT: sprintf(prim,"%d" ,*((int *)value)); line += prim; break;
+ case TRACETYPE_INT: sprintf(prim,"%d" ,*((int *)value)); line += prim; break;
case TRACETYPE_ULONG: sprintf(prim,"%lu",*((long *)value)); line += prim; break;
case TRACETYPE_LONG: sprintf(prim,"%ld",*((long *)value)); line += prim; break;
case TRACETYPE_UDOUBLE: sprintf(prim,"%Lu",*((double*)value)); line += prim; break;
1.28 +21 -29 ws-axis/c/src/common/AxisTrace.h
Index: AxisTrace.h
===================================================================
RCS file: /home/cvs/ws-axis/c/src/common/AxisTrace.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- AxisTrace.h 20 Jan 2005 11:23:18 -0000 1.27
+++ AxisTrace.h 3 Feb 2005 09:55:59 -0000 1.28
@@ -31,20 +31,15 @@
#include <stdarg.h>
#if defined(ENABLE_AXISTRACE)
- #define AXISTRACE1(X, Y) AxisTrace::logaxis(X,Y,__FILE__,__LINE__);
- #define AXISTRACE2(X, Y, Z) AxisTrace::logaxis(X,Y,Z,__FILE__,__LINE__);
+ #define AXISTRACE1(X, L) AxisTrace::logaxis(X,NULL,"W",__FILE__,__LINE__);
+ #define AXISTRACE2(X, Y, L) AxisTrace::logaxis(X,Y,"W",__FILE__,__LINE__);
#define AXISTRACE3(X) AxisTrace::trace(X);
#else
- #define AXISTRACE1(X,Y)
- #define AXISTRACE2(X,Y,Z)
+ #define AXISTRACE1(X,L)
+ #define AXISTRACE2(X,Y,L)
#define AXISTRACE3(X)
#endif
-typedef enum
-{
- CRITICAL=1, WARN, INFO, TRIVIAL
-} AXIS_SEVERITY_LEVEL;
-
/**
* @class AxisTrace
* @brief This is class is used to log messages when AXISTRACE is defined.
@@ -80,6 +75,17 @@
#define TRACETYPE_EXCEPTION 17
#define TRACETYPE_AXISEXCEPTION 18
+#define TRACE_ENTRY ">"
+#define TRACE_EXIT "<"
+#define TRACE_AUDIT "A"
+#define TRACE_DEBUG "D"
+#define TRACE_EVENT "E"
+#define TRACE_INFO "I"
+#define TRACE_SYSOUT "O"
+#define TRACE_UNCOND "U"
+#define TRACE_WARN "W"
+#define TRACE_EXCEPT "X"
+
class AxisTraceEntrypoints {
public:
void (*m_traceLine)(const char *data);
@@ -110,23 +116,6 @@
/**
* This is called in writing to the log file whose path is specified in
- * $AXIS_HOME/axiscpp.conf file.
- * This method is used when the caller has only one
- * string message as argument. User
- * can also specify the severity of the message by assigning level
- * argument to one
- * of CRITICAL, WARN, INFO or TRIVIAL.
- * @param sLog string message
- * @param level severity level
- * @param arg2 file name
- * @param arg3 line number
- * @return The status which indicates whether the operation is success
- * (AXIS_SUCCESS) or not (AXIS_FAIL).
- */
- static int logaxis(const char* sLog, int level, char* arg2, int arg3);
-
- /**
- * This is called in writing to the log file whose path is specified in
* $AXIS_HOME/axiscpp.c * onf file.
* This method is used when the caller has two string messages
* as arguments. One may be his *own message.
@@ -141,8 +130,8 @@
* @return The status which indicates whether the operation is success
* (AXIS_SUCCESS) or not * (AXIS_FAIL).
*/
- static int logaxis(const char* sLog1, const char* sLog2, int level, char* arg3,
- int arg4);
+ static int logaxis(const char* sLog1, const char* sLog2,
+ const char *type, char* file, int line);
/**
* Writes the given string to the standard console.
@@ -192,6 +181,9 @@
static inline void traceLine(const char *data) {(*g_traceEntrypoints->m_traceLine)(data); }
#else
static inline void traceLine(const char *data) {traceLineInternal(data);}
+ static void traceLineInternal(const char *type, const char *classname,
+ const char *methodname, const void *that,
+ const char *parms);
#endif
static void traceLineInternal(const char *data);
@@ -286,12 +278,12 @@
private:
static bool m_bLoggingOn;
static AxisFile *m_fileTrace;
- static std::stack<std::string> m_stack;
static int logthis(const char* pcLog, int level, char* arg2, int arg3);
static void addParameter(std::string& line, int type, unsigned len, void *value);
static void addDataParameter(std::string& line, unsigned len, void *value);
static void traceHeader();
+ static void traceLine2(const char *data);
};
AXIS_CPP_NAMESPACE_END