Using Trace
These are the basic steps required to generate trace output:
4. Choose a combination of compile time and runtime options for controlling the severity levels of the events reported. (See
Controlling Trace Output.)
Example 49 illustrates the steps required to generate trace output in a global function. The following code is taken from
buildspace\examples\trace\helloTrace.cpp.
Example 49 – Generating trace output
#define RW_USER_TRACE_LEVEL 8 //1
#include <rw/trace/trace.h> //2
// Create a trace client that logs messages to cerr
RWTraceOstreamClient myTraceClient(cerr); //3
int main()
{
// Declare the function as traceable and use
// the environment variable named "main” to control
// trace event generation from this function
RW_USER_TRACEABLE_FUNCTION("main”); //4
// Connect the client to the singleton manager
myTraceClient.connectToManager(); //5
// Generate some trace events
RW_USER_TRACE_DEBUG("This is a debug message”); //6
RW_USER_TRACE_INFO("This is an informational message”); //7
return 0;
}
To see output, set the main or rw_user environment variable to ON. rw_user works because the main() function is declared on line //3 to be a member of the predefined rw_user package set. The program produces this output:
ENTRY|helloTrace.cpp:10|main> Entry
DEBUG|helloTrace.cpp:19|main> This is a debug message
INFO|helloTrace.cpp:20|main> This is an informational message
EXIT|helloTrace.cpp:25|main> Exit