The class must be initialized by calling the special, three argument version of the constructor. This is usually done in the main
subroutine.
int main( int argc, char * argv[] ) { TraceFct tf( argv[0], 0, -1 );
Thereafter, use the one-argument constructor when entering a new subroutine to be traced.
void f2( void ) { static int level = 0; TraceFct tf( "f2" );
TraceFct
provides several methods to output warning or diagnostic messages as well as produce a function stack dump upon an error exit. The benefit of using the output methods is that all output will have a common, unique prefix, which permits easier analysis of complicated log files. Messages may have embedded newlines.
tf.message( "message test: %d\n", level ); tf.message( "1. multiline\n2. message test\n" );
Currently TraceFct
does not have an overloaded <<
operator; use the TraceFct::message() and TraceFct::vmessage() methods.
To generate a stack dump upon exit, use the TraceFct::exit() method.
tf.exit( 1, "f1 exit: line1\nf1 exit: line2, extra newline\n" );
To generate just a stack dump, just call TraceFct::dump_stack().