// TestTableLimit.cc -- Illustration of using the setTableLimit feature of // 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. // // We utilize the basicUaage.h header; the only difference is in the way // this framework sets things up. // ----------------- // Physicsists' Code // ----------------- #include "basicUsage.h" #include "ErrorLogger/ErrorLog.h" #include "ZMutility/sstream" void DoPhysics::operator()( Event & event ) { for (int i = 1; i <= event.data; i++) { std::ostringstream oss; oss << "Error ID " << i; errlog (ELerror, oss.str()) << "in event number " << 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 ) USING( std::cin ) Module::Module( const std::string & name ) { errlog.setModule( name ); } int main() { int events; cout << "Please enter number of events: "; cin >> events; int limit; cout << "Please enter repetition limit for output: "; cin >> limit; int tlimit; cout << "Please enter table limit for output: "; cin >> tlimit; int flimit; cout << "Please enter repetition limit for logfile: "; cin >> flimit; int ftlimit; cout << "Please enter table limit for logfile: "; cin >> ftlimit; ELadministrator * logger = ELadministrator::instance(); // instantiate a logger object ELoutput logfileD( "testTableLimit.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 output.setLimit("*", limit); output.setTableLimit(tlimit); logfile.setLimit("*", flimit); logfile.setTableLimit(ftlimit); // 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 <= events; ++n ) { Event event( n ); doPhysics( event ); } return 0; } // main()