// ---------------------------------------------------------------------- // // elxLogViaErrTest.cc // // Usage sample of the mechanism to route ZMexceptions output to an ErrorLog. // // Intent: There will be a class, ultimately derived from ZMexception, // named XRCP. // // Other exception classes will be derived from XRCP, for example, // XRCPBadPath. // // The framework sets up an ErrorLog, here called // errlog // // User code (or RCP code) will ZMthrow this sort of exception: // e.g., ZMthrow (XRCPBadPath ("Path is /usr/h0me/mp/inc"); // // The resulting text will be routed to the errlog. // // ---------------------------------------------------------------------- #include "ZMutility/ZMenvironment.h" #include "Exceptions/ZMthrow.h" #include "ErrorLogger/ELadministrator.h" #include "ErrorLogger/ELoutput.h" #include "ErrorLogger/ELstatistics.h" #include "ErrorLogger/ELdestControl.h" #include "ErrorLogger/ErrorLog.h" #include "ErrLogEx/ZMexViaErrlog.h" #include "ZMutility/iostream" #include "Exceptions/ZMexception.h" // ------------------------------------------------------------------------ // // Declarations/definitions of app-specific ZMexceptions // These would tend to be in .h file // Base class for all XRCP exceptions ZMexStandardDefinition( ZMexception, XRCP ); // And several specific exceptions inheriting from XRCP: ZMexStandardDefinition( XRCP, XRCPBadPath ); ZMexStandardDefinition( XRCP, XRCPSyntaxError ); // ------------------------------------------------------------------------ ZM_USING_NAMESPACE(zmel) ZM_USING_NAMESPACE(zmex) // ========================================================================= // Definitions of the various XRCP ZMexceptions: // These need to be in a .cc file; in this usage sample there is only // this one .cc file. ZMexClassInfo XRCP::_classInfo( "XRCP", // An XRCP thrown will be named XRCP in the output, "RCP:", // will be said to come from the RCP facility, ZMexSEVERE // will be assigned a severity of SEVERE ); ZMexClassInfo XRCPBadPath::_classInfo("Bad RCP Path", "RCP:", ZMexWARNING); ZMexClassInfo XRCPSyntaxError::_classInfo ("RCP Syntax Error", "RCP:", ZMexERROR ); int main() { // This illustrates the desired case: Since the code will have done // XRCP::setLogger( ZMexViaErrlog(log) ) // these exceptions will be routed to that ErrorLog. ELadministrator * boss = ELadministrator::instance(); // make the controller ELoutput screenD ( std::cout ); // make the 1st destination ... ELstatistics statsD ( std::cout ); // and a statistics destination ... ELdestControl screen = boss->attach( screenD ); ELdestControl stats = boss->attach( statsD ); ErrorLog log; // make the logger ... log.setModule( "tXRCP ZMexceptions" ); // ... & clue it in XRCP::setLogger( ZMexViaErrlog(log) ); // instruct XRCP to log // itself this way screen.suppressTime(); // The time output is somewhat redundant since // the Exception message also contains the time screen.suppressModule(); // The module name output may be useful or not. ZMthrow( XRCPBadPath ("Test message #2") ); ZMthrow( XRCPBadPath ("Test message #3") ); ZMthrow( XRCPBadPath ("Test message #4") ); // ZMthrow( XRCPSyntaxError ("Test message #5") ); // This last one will cause an uncaught exception because its severity is ERROR stats.summary( screen, "Your Requested Summary:" ); // --- go home: // return 0; } // main()