// debugLevel.cc -- Illustration of using the debugVerbosityLevel features of // ErrorLogger mechanism. // // Based on basicUsage.cc // // This example program is in two logical pieces: // // First we show the user code -- many physicist users could contribute // code of this nature, using errlog in the manner shown. // // Then we show the framework code that would support this. One // programmer sets up this framework to coordinate all code. The // framework controls things like which output destinations exist and // what sort of messages to pass to each destination -- and in this // case, debug verbosity levels. // // ----------------- // Physicsists' Code // ----------------- #include "debugLevel.h" #include "ErrorLogger/ErrorLog.h" void DoPhysics::operator()( Event & event ) { static int v; // THIS METHOD IS WHERE ALL THE PHYSICS CALCULATION WOULD GO. errlog( ELsuccess, "An Event" ) << "data = " << event.data << endmsg; if ( (event.data&1)==0 ) { v = event.data/2; errlog.setDebugVerbosity (v); // Note -- this is good for the test program. // But normally, the framework should take care of all setting of // verbosity etc. for the errlog -- not the physicist code. } if ( ( event.data==11) ) { errlog.setDebugMessages (ELwarning, "fixit"); } for (int i = 0; i <= 10; i++) { errlog (i) << "verbosity level is " << v << " debug level is " << i << endmsg; } errlog (ELsuccess, "Event Finished") << "event # " << event.data << endmsg; } // DoPhysics::operator()(event) // --------------- // Framework Code // --------------- #include "ErrorLogger/ELadministrator.h" #include "ErrorLogger/ELdestControl.h" #include "ErrorLogger/ELoutput.h" #include "ErrorLogger/ELstatistics.h" #include "ZMutility/iostream" USING( std::cout ) Module::Module( const std::string & name ) { errlog.setModule( name ); } int main() { ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ELoutput outputD( cout ); ELdestControl output ( logger->attach(outputD) ); output.setThreshold ( ELzeroSeverity ); ELstatistics statsD( cout ); // a statistics dest ELdestControl stats ( logger->attach(statsD) ); // tell logger about it // The following is a list of the modules in this program: DoPhysics doPhysics( "PHYSICS CODE" ); // There is only one module in this illustration. int n; for ( n = 1; n < 20; ++n ) { Event event( n ); doPhysics( event ); if (n%8 == 0) { stats.summary( output, "Error Statistics So Far" ); } } return 0; } // main()