MsgLogger/include/MsgFormatter.h

Go to the documentation of this file.
00001 #ifndef MSGFORMATTER_HH
00002 #define MSGFORMATTER_HH
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: MsgFormatter.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class MsgFormatter.
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 #include <map>
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 MsgLogRecord ;
00056 
00057 
00058 /**
00059  *  @ingroup MsgLogger
00060  *
00061  *  The class which does message formating to show the message in  the
00062  *  human-readable format. In principle you can inherit this class and
00063  *  override some methods, but this implementation is already sufficiently
00064  *  generic and can be controlled completely via the format strings.
00065  *
00066  *  This software was developed for the BaBar collaboration.  If you
00067  *  use all or part of it, please give an appropriate acknowledgement.
00068  *
00069  *  Copyright (C) 2005 SLAC
00070  *
00071  *  @see MsgHandler
00072  *
00073  *  @version $Id: MsgFormatter.h 2700 2011-12-09 21:52:07Z salnikov@SLAC.STANFORD.EDU $
00074  *
00075  *  @author Andy Salnikov
00076  */
00077 
00078 class MsgFormatter {
00079 
00080 public:
00081 
00082   // Constructor
00083   MsgFormatter( const std::string& fmt = "", const std::string& timefmt = "" ) ;
00084 
00085   // Destructor
00086   virtual ~MsgFormatter() ;
00087 
00088   // set format for all formatters
00089   static void addGlobalFormat ( const std::string& fmt ) ;
00090   static void addGlobalFormat ( MsgLogLevel level, const std::string& fmt ) ;
00091 
00092   // add level-specific format
00093   virtual void addFormat ( MsgLogLevel level, const std::string& fmt ) ;
00094 
00095   // format message to the output stream
00096   virtual void format ( const MsgLogRecord& rec, std::ostream& out ) ;
00097 
00098 protected:
00099 
00100   // get a format string for a given level
00101   virtual const std::string& getFormat ( MsgLogLevel level ) const ;
00102 
00103 private:
00104 
00105   // Data members
00106   std::string _timefmt ;
00107   std::string _fmtMap[MsgLogLevel::LAST_LEVEL+1] ;
00108 
00109   // Disable copy
00110   MsgFormatter( const MsgFormatter& );
00111   MsgFormatter& operator= ( const MsgFormatter& );
00112 
00113 };
00114 } // namespace MsgLogger
00115 
00116 #endif // MSGFORMATTER_HH

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7