00001 #ifndef MSGHANDLER_HH 00002 #define MSGHANDLER_HH 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: MsgHandler.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class MsgHandler. 00010 // 00011 // Environment: 00012 // This software was developed for the BaBar collaboration. If you 00013 // use all or part of it, please give an appropriate acknowledgement. 00014 // 00015 // Author List: 00016 // Andy Salnikov 00017 // 00018 // Copyright Information: 00019 // Copyright (C) 2005 SLAC 00020 // 00021 //------------------------------------------------------------------------ 00022 00023 //------------- 00024 // C Headers -- 00025 //------------- 00026 extern "C" { 00027 } 00028 00029 //--------------- 00030 // C++ Headers -- 00031 //--------------- 00032 #include <iostream> 00033 #include <string> 00034 00035 //---------------------- 00036 // Base Class Headers -- 00037 //---------------------- 00038 00039 //------------------------------- 00040 // Collaborating Class Headers -- 00041 //------------------------------- 00042 #include "MsgLogger/MsgLogLevel.h" 00043 00044 //------------------------------------ 00045 // Collaborating Class Declarations -- 00046 //------------------------------------ 00047 00048 // --------------------- 00049 // -- Class Interface -- 00050 // --------------------- 00051 00052 00053 namespace MsgLogger { 00054 00055 class MsgFormatter ; 00056 class MsgLogRecord ; 00057 00058 /** 00059 * @ingroup MsgLogger 00060 * 00061 * The base class for handling messages. Handling means dispatching 00062 * messages to their final distantion, such as terminal, log file, 00063 * external logging service, etc. Handlers like loggers have corresponding 00064 * logging level which can be changed by clients. Default logging 00065 * level for handlers is debug, which means they will log whatever 00066 * loggers give them. For formatting the messages handlers use 00067 * MsgFormatter class, clients can attach their own formatter objects to 00068 * handlers, otherwise default formatter class will be used. 00069 * 00070 * This software was developed for the BaBar collaboration. If you 00071 * use all or part of it, please give an appropriate acknowledgement. 00072 * 00073 * Copyright (C) 2005 SLAC 00074 * 00075 * @see MsgLogger 00076 * 00077 * @version $Id: MsgHandler.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $ 00078 * 00079 * @author Andy Salnikov 00080 */ 00081 00082 class MsgHandler { 00083 00084 public: 00085 00086 // Destructor 00087 virtual ~MsgHandler() ; 00088 00089 /// attaches the formatter, will be owned by handler 00090 virtual void setFormatter ( MsgFormatter* formatter ) ; 00091 00092 /// set the logger level, messages with the level below this won't be logged 00093 virtual void setLevel ( MsgLogLevel level ) ; 00094 00095 /// check if the specified level will log any message 00096 virtual bool logging ( MsgLogLevel sev ) const ; 00097 00098 /// get the stream for the specified log level 00099 virtual bool log ( const MsgLogRecord& record ) const = 0 ; 00100 00101 protected: 00102 00103 // Constructor 00104 MsgHandler() ; 00105 00106 // get the formatter 00107 MsgFormatter& formatter() const ; 00108 00109 private: 00110 00111 // Data members 00112 mutable MsgFormatter* _formatter ; 00113 MsgLogLevel _level ; 00114 00115 // Disable copy 00116 MsgHandler( const MsgHandler& ); 00117 MsgHandler& operator= ( const MsgHandler& ); 00118 00119 }; 00120 } // namespace MsgLogger 00121 00122 #endif // MSGHANDLER_HH