// testDiscard -- Illustration of using the setDiscardThreshold features // ErrorLogger mechanism. // // 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. // // THIS FRAMEWORK IS A VERY MINIMAL EXAMPLE for illustration. // // ----------------- // Physicsists' Code // ----------------- #include "testDiscard.h" #include "ErrorLogger/ErrorLog.h" void DoPhysics::operator()( Event & event ) { int n = 1; if (event.data < 99) { if (event.data==4) { // Here is the key line in this test: errlog.setDiscardThreshold (ELsuccess); // <-------------------- } // a bunch of messages: errlog( ELincidental, "incidental" ) << "data " << n++ << endmsg; errlog( ELsuccess, "success" ) << "data " << n++ << endmsg; errlog( ELinfo, "info" ) << "data " << n++ << endmsg; errlog( ELwarning, "warning" ) << "data " << n++ << endmsg; errlog( ELwarning2, "warning2" ) << "data " << n++ << endmsg; errlog( ELerror, "error" ) << "data " << n++ << endmsg; errlog( ELerror2, "error2" ) << "data " << n++ << endmsg; errlog( ELsevere, "severe" ) << "data " << n++ << endmsg; errlog( ELsevere, "severe2" ) << "data " << n++ << endmsg; // What a useless routine! return; } if (event.data==400) errlog.setDiscardThreshold (ELerror2); // <---------- if (event.data > 99) { // Here is where the timing is tested: for (int k=0; k<100; k++) { errlog( ELwarning, "warning" ) << "data " << n++ << n++ << endmsg; } } } // DoPhysics::operator()(event) // --------------- // Framework Code // --------------- #include "testDiscard.h" #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 ); errlog.setDiscardThreshold(ELwarning); // <--------------------------- } int main() { ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ELoutput logfileD( "testDiscard.errlog" ); // make an ELdestination ELdestControl logfile ( logger->attach(logfileD) ); // tell logger about it logfile.setThreshold ( ELsuccess ); // ignore messages below // ELsucess ELoutput outputD( cout ); // another ELdestination ELdestControl output ( logger->attach(outputD) ); // tell logger about it output.setThreshold ( ELerror ); // ignore messages below // ELerror ELstatistics statsD( cout ); // a statistics dest ELdestControl stats ( logger->attach(statsD) ); // tell logger about it stats.setThreshold ( ELerror ); // ignore messages below // ELerror // 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 = 1; for ( ; n < 4; ++n ) { Event event( n ); doPhysics( event ); } for ( ; n < 7; ++n ) { Event event( n ); doPhysics( event ); } logfile.setThreshold ( ELsevere ); std::cout << "\n\n TIMING TEST 1 STARTS NOW! \n\n"; for ( n=100; n < 400; ++n ) { Event event( n ); doPhysics( event ); } std::cout << "\n\n TIMING TEST 1 FINISHED NOW! \n\n"; std::cout << "\n\n TIMING TEST 2 STARTS NOW! \n\n"; for ( n=400; n < 4400; ++n ) { Event event( n ); doPhysics( event ); } std::cout << "\n\n TIMING TEST 1 FINISHED NOW! \n\n"; // Because statsD was given an argument of cout when constructed, one // last summary will be sent to cout when the job terminates. return 0; } // main()