00001 #ifndef MSGLOGGER_HH 00002 #define MSGLOGGER_HH 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: MsgLogger.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class MsgLogger. 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 acknowledgment. 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/MsgLogStream.h" 00043 00044 //------------------------------------ 00045 // Collaborating Class Declarations -- 00046 //------------------------------------ 00047 00048 // --------------------- 00049 // -- Class Interface -- 00050 // --------------------- 00051 00052 namespace MsgLogger { 00053 00054 class MsgHandler ; 00055 class MsgLogRecord ; 00056 class MsgLoggerImpl ; 00057 00058 /** 00059 * @ingroup MsgLogger 00060 * 00061 * The class for the first-level processing of the messages. The streams 00062 * send messages to this class, and this class forwards them to handlers 00063 * (if it decides that message is indeed to be logged.) The loggers are 00064 * organized into hierarchical structure, every logger has a parent, except 00065 * one root logger which does not have any parents. Every message is also sent 00066 * by logger to its parent logger, unless propagate flag is clear. 00067 * 00068 * Note that this class is just a kind of smart poiner class for the 00069 * real objects of the class MsgLoggerImpl which do real job. 00070 * 00071 * This software was developed for the BaBar collaboration. If you 00072 * use all or part of it, please give an appropriate acknowledgment. 00073 * 00074 * Copyright (C) 2005 SLAC 00075 * 00076 * @see MsgLoggerImpl 00077 * 00078 * @version $Id: MsgLogger.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $ 00079 * 00080 * @author Andy Salnikov 00081 */ 00082 00083 class MsgLogger { 00084 00085 public: 00086 00087 // Construct named logger, or root logger for empty name 00088 MsgLogger( const std::string& name = "" ) ; 00089 00090 // default copy ctor is OK 00091 //MsgLogger( const MsgLogger& ); 00092 00093 // Destructor 00094 ~MsgLogger() {} 00095 00096 // default assignment is OK 00097 //MsgLogger& operator= ( const MsgLogger& ); 00098 00099 /// set the logger level, messages with the level below this won't be logged 00100 void setLevel ( MsgLogLevel level ) ; 00101 00102 /// define whether or not we need messages propagated to ancestors 00103 void propagate ( bool flag ) ; 00104 00105 /// add a handler for the messages, takes ownership of the object 00106 void addHandler ( MsgHandler* handler ) ; 00107 00108 /// check if the specified level will log any message 00109 bool logging ( MsgLogLevel sev ) const ; 00110 00111 /// get the stream for the specified log level 00112 bool log ( const MsgLogRecord& record ) const ; 00113 00114 protected: 00115 00116 // Helper functions 00117 00118 private: 00119 00120 // Friends 00121 00122 // Data members 00123 MsgLoggerImpl* const _impl ; // Pointer to the real implementation 00124 00125 }; 00126 } // namespace MsgLogger 00127 00128 #endif // MSGLOGGER_HH