Using RWTraceMultiClientFilter
Sometimes it is desirable to connect multiple clients to the manager or a filter. The RWTraceMultiClientFilter class facilitates this. Example 55 creates two clients; one displays messages on the screen, and the other saves them to a file. This example can be found in buildspace\examples\trace\example2.cpp.
Example 55 – Using two trace clients
#define RW_USER_TRACE_LEVEL 8
#include <rw/trace/trace.h>
 
#include <fstream.h>
 
int main()
{
ofstream traceLog("trace.log");
RWTraceOstreamClient myFileTraceClient(traceLog);
RWTraceOstreamClient myCerrTraceClient(cerr);
 
RWTraceMultiClientFilter myMultiFilter; // 1
 
// first: connect two clients to multi client filter
myFileTraceClient.connect(myMultiFilter); // 2
myCerrTraceClient.connect(myMultiFilter);
// last: connect filter to singleton manager
myMultiFilter.connectToManager(); // 3
 
RW_USER_TRACEABLE_FUNCTION("main”); // 4
 
RW_USER_TRACE_DEBUG("Picked up pencil.");
RW_USER_TRACE_TEST("Visual inspection of pencil complete.");
RW_USER_TRACE_INFO("Doodling!");
...
return 0;
}
 
//1 Instantiates the multi-client filter.
//2 First connects the two clients to the filter.
//3 Then connects the filter to the manager to ensure that no trace messages are lost.
//4 Generates some trace messages.