SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
A handle class for a single-client filter that lets events only of the supplied severity level or higher to pass through. More...
#include <rw/trace/RWTraceLevelFilter.h>
Public Member Functions | |
RWTraceLevelFilter (RWTraceEventSeverity level=RW_TRACE_LEVEL_NONE) | |
RWTraceLevelFilter (RWTraceLevelFilterImp *bodyP) | |
RWTraceLevelFilter (RWStaticCtor) | |
RWTraceLevelFilter (const RWTraceLevelFilter &second) | |
~RWTraceLevelFilter (void) | |
RWTraceEventSeverity | getLevel () const |
void | setLevel (RWTraceEventSeverity level) |
RWTraceLevelFilter is a single-client trace filter that accepts events only of the supplied severity level or higher, and forwards them to a client.
This example is located in your installation directory at examples/trace/LevelFilter.cpp
.
#define RW_USER_TRACE_LEVEL 8 //1 #include <rw/trace/trace.h> int main(void) { // declare function as traceable with the set name "main" // this also generates an entry/exit event RW_USER_TRACEABLE_FUNCTION("main"); //2 // create trace client that logs messages to cerr RWTraceOstreamClient client(cerr); //3 // create filter that lets only INFO and more important // events pass through RWTraceLevelFilter levelFilter(RW_TRACE_LEVEL_INFO); //4 // connect client to level filter client.connect(levelFilter); //5 // connect level filter to manager levelFilter.connectToManager(); //6 // generate some trace information; these trace events // will belong to the sets "rw_user" and "main" RW_USER_TRACE_DEBUG("Debug (hidden)"); RW_USER_TRACE_TEST("Test (hidden)"); RW_USER_TRACE_INFO("Info"); RW_USER_TRACE_WARNING("Warning"); RW_USER_TRACE_ERROR("Error"); RW_USER_TRACE_FATAL("Fatal"); // change the level levelFilter.setLevel(RW_TRACE_LEVEL_ERROR); //7 // generate some more trace information; these trace // events will belong to the sets "rw_user" and "main" RW_USER_TRACE_DEBUG("Debug (hidden)"); RW_USER_TRACE_TEST("Test (hidden)"); RW_USER_TRACE_INFO("Info (hidden)"); RW_USER_TRACE_WARNING("Warning (hidden)"); RW_USER_TRACE_ERROR("Error"); RW_USER_TRACE_FATAL("Fatal"); return 0; }
//1
Compile in all trace macros by setting the user trace level macro to 8, the maximum (Entry/Exit) level. You can also define the trace level on the command line for your compiler, using the flag -DRW_USER_TRACE_LEVEL=8
.
//2
Declare the function as traceable, so you can use trace event generation macros in this function.
//3
Create a normal std::ostream client to display the trace information.
//4
Instantiate an RWTraceLevelFilter. The constructor takes the minimum severity (i.e. the maximum level) of trace messages to pass through. You can pass an integer level number cast to RWTraceEventSeverity or use one of the symbolic constants, as in this line. Pass RW_TRACE_LEVEL_NONE to filter out all trace messages. See the discussion on trace level filters in the Threads Module User's Guide for a definition of the severity levels.
//5
Connect the client to the level filter.
//6
Then connect the filter to the trace manager.
//7
Change the cutoff level on the level filter, using the setLevel() function.
All of these constants map directly to the appropriate severity level. RW_TRACE_LEVEL_NONE filters out all trace messages. It is equivalent to zero.
RWTraceLevelFilter::RWTraceLevelFilter | ( | RWTraceEventSeverity | level = RW_TRACE_LEVEL_NONE |
) |
Default constructor. If no level is supplied, the default is RW_TRACE_LEVEL_NONE. In this case, no events are passed on.
RWTraceLevelFilter::RWTraceLevelFilter | ( | RWTraceLevelFilterImp * | bodyP | ) |
Attaches to and increments the reference count on bodyP.
RWTraceLevelFilter::RWTraceLevelFilter | ( | RWStaticCtor | ) |
Constructs a global static handle instance (that may be used before being constructed).
RWTraceLevelFilter::RWTraceLevelFilter | ( | const RWTraceLevelFilter & | second | ) |
Attaches to and increments the reference count on the body of second.
RWTraceLevelFilter::~RWTraceLevelFilter | ( | void | ) |
Destructor.
RWTraceEventSeverity RWTraceLevelFilter::getLevel | ( | ) | const |
Returns the filter's severity level.
void RWTraceLevelFilter::setLevel | ( | RWTraceEventSeverity | level | ) |
Sets the severity level for the filter.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.