MsgLogger/include/MsgLoggerImpl.h

Go to the documentation of this file.
00001 #ifndef MSGLOGGERIMPL_HH
00002 #define MSGLOGGERIMPL_HH
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: MsgLoggerImpl.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class MsgLoggerImpl.
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 #include <vector>
00035 
00036 //----------------------
00037 // Base Class Headers --
00038 //----------------------
00039 
00040 //-------------------------------
00041 // Collaborating Class Headers --
00042 //-------------------------------
00043 #include "MsgLogger/MsgLogLevel.h"
00044 
00045 //------------------------------------
00046 // Collaborating Class Declarations --
00047 //------------------------------------
00048 
00049 //              ---------------------
00050 //              -- Class Interface --
00051 //              ---------------------
00052 
00053 namespace MsgLogger {
00054 
00055 class MsgHandler ;
00056 class MsgLogRecord ;
00057 
00058 /// @addtogroup MsgLogger_detail
00059 
00060 /**
00061  *  @ingroup MsgLogger_detail
00062  *
00063  *  Implementation of the message logger. This class is actually an implementation
00064  *  detail used by the MsgLogger class. It should not be visible to clients in any way.
00065  *
00066  *  This software was developed for the BaBar collaboration.  If you
00067  *  use all or part of it, please give an appropriate acknowledgment.
00068  *
00069  *  Copyright (C) 2005 SLAC
00070  *
00071  *  @see MsgLogger
00072  *  @see MsgHandler
00073  *
00074  *  @version $Id: MsgLoggerImpl.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $
00075  *
00076  *  @author Andy Salnikov
00077  */
00078 
00079 class MsgLoggerImpl {
00080 
00081 public:
00082 
00083   // Construct named logger
00084   MsgLoggerImpl( const std::string& name ) ;
00085 
00086   // default copy ctor is OK
00087   //MsgLoggerImpl( const MsgLoggerImpl& );
00088 
00089   // Destructor
00090   ~MsgLoggerImpl();
00091 
00092   // default assignment is OK
00093   //MsgLoggerImpl& operator= ( const MsgLoggerImpl& );
00094 
00095   /// set the logger level, messages with the level below this won't be logged
00096   void setLevel ( MsgLogLevel level ) { _level = level ; }
00097 
00098   /// define whether or not we need messages propagated to ancestors, root logger never propagates
00099   void propagate ( bool flag ) { if ( ! _name.empty() ) _propagate = flag ; }
00100 
00101   /// add a handler for the messages, takes ownership of the object
00102   void addHandler ( MsgHandler* handler ) ;
00103 
00104   /// name of the logger
00105   const std::string name() const { return _name ; }
00106 
00107   /// check if the specified level will log any message
00108   bool logging ( MsgLogLevel sev ) const ;
00109 
00110   /// get the stream for the specified log level
00111   bool log ( const MsgLogRecord& record ) const ;
00112 
00113   /// send the message to the handles and parents
00114   void handle ( MsgLogRecord& record ) const ;
00115 
00116 protected:
00117 
00118 private:
00119 
00120   // Types
00121   typedef std::vector<MsgHandler*> HandlerList ;
00122 
00123   // Data members
00124   std::string _name ;
00125   MsgLogLevel _level ;
00126   mutable bool _propagate ;
00127   mutable MsgLoggerImpl* _parent ;
00128   HandlerList _handlers ;
00129 
00130 //------------------
00131 // Static Members --
00132 //------------------
00133 
00134 public:
00135 
00136   static MsgLoggerImpl* getLogger( const std::string& name ) ;
00137 
00138 };
00139 } // namespace MsgLogger
00140 
00141 #endif // MSGLOGGERIMPL_HH

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7