PSQt/include/LoggerBase.h

Go to the documentation of this file.
00001 #ifndef LOGGERBASE_H
00002 #define LOGGERBASE_H
00003 
00004 //--------------------------
00005 #include <map>
00006 #include <iostream>    // std::cout
00007 #include <fstream>     // std::ifstream(fname)
00008 #include <sstream>     // stringstream
00009  
00010 namespace PSQt {
00011 
00012 //--------------------------
00013 /**
00014  *  @ingroup PSQt LEVEL
00015  *
00016  *  @brief LEVEL - enumerator of message types/levels
00017  */ 
00018 
00019 enum LEVEL {DEBUG=0, INFO, WARNING, CRITICAL, ERROR, NONE};
00020 
00021 //--------------------------
00022 /**
00023  *  @ingroup PSQt Record
00024  *
00025  *  @brief Record - struct for LoggerBase records
00026  */ 
00027 
00028 struct Record {
00029   unsigned    number;
00030   double      time;
00031   std::string tstamp; 
00032   LEVEL       level;
00033   std::string name; 
00034   std::string msg; 
00035 
00036   std::string strRecordTotal();
00037   std::string strRecordBrief();
00038   std::string strRecord();
00039 };
00040 
00041 //--------------------------
00042 
00043 std::string strLevel(const LEVEL& level=DEBUG) ;
00044 LEVEL levelFromString(const std::string& str="INFO");
00045 std::string strTimeStamp(const std::string& format=std::string("%Y-%m-%d-%H:%M:%S"));
00046 double doubleTimeNow();
00047 
00048 //--------------------------
00049 
00050 // @addtogroup PSQt LoggerBase
00051 
00052 /**
00053  *  @ingroup PSQt LoggerBase
00054  *
00055  *  @brief Base class for messaging system.
00056  *
00057  *  Accumulates messages as records in std::map<unsigned, Record> m_sslog;
00058  *  new_record(Record& rec) - callback for re-implementation in subclass.
00059  *  This class enherited by Logger.
00060  *
00061  *  This software was developed for the LCLS project.  If you use all or 
00062  *  part of it, please give an appropriate acknowledgment.
00063  *
00064  *  @see Logger, GUILogger, GUIMain
00065  *
00066  *  @version $Id: LoggerBase.h 9841 2015-03-26 18:35:44Z dubrovin@SLAC.STANFORD.EDU $
00067  *
00068  *  @author Mikhail Dubrovin
00069  *
00070  *
00071  *
00072  *
00073  *
00074  *  @anchor interface
00075  *  @par<interface> Interface Description
00076  * 
00077  *  @li  Include
00078  *  @code
00079  *  #include "PSQt/LoggerBase.h"
00080  *  @endcode
00081  *
00082  *  @li Instatiation
00083  *  \n
00084  *  LoggerBase is inhereted and used by the class Logger
00085  */
00086 
00087 //--------------------------
00088 
00089 class LoggerBase
00090 {
00091  public:
00092 
00093   /**
00094    *  @brief Base class for message logger
00095    *  
00096    *  @param[in] level - threshold level for collected messages. Messages with level lover than threshold are ignored.
00097    */ 
00098     LoggerBase(const LEVEL& level=INFO); 
00099     virtual ~LoggerBase(){}; 
00100 
00101     void message(const std::string& name=std::string(), const LEVEL& level=INFO, const std::string& msg=std::string());
00102     void message(const std::string& name=std::string(), const LEVEL& level=INFO, const std::stringstream& ss=std::stringstream());
00103     void print(const std::string& str=std::string());
00104     void setLevel(const LEVEL& level=INFO);
00105     LEVEL getLevel() { return m_level; }
00106     void saveLogInFile(const std::string& fname=std::string(), const bool& add_tstamp=true) ;
00107     std::string strRecordsForLevel(const LEVEL& thr=INFO);
00108 
00109  protected:
00110     virtual void new_record(Record& rec);
00111 
00112  private:
00113 
00114     unsigned    m_recnum;
00115     LEVEL       m_level;
00116     std::string m_start_tstamp;
00117     double      m_start_time;
00118 
00119     std::map<unsigned, Record> m_sslog;
00120 
00121     inline const char* _name_(){return "LoggerBase";}
00122     void startLoggerBase();
00123     std::string getFileName(const std::string& fname=std::string(), const bool& add_tstamp=true);
00124 };
00125 
00126 //--------------------------
00127 
00128 //#define MsgInLog     LoggerBase::getLoggerBase()->message
00129 //#define PrintMsg     LoggerBase::getLoggerBase()->print
00130 //#define SetMsgLevel  Logger::getLogger()        ->setLevel
00131 //#define SaveLog      LoggerBase::getLoggerBase()->saveLogInFile
00132 
00133 //--------------------------
00134 
00135 } // namespace PSQt
00136 
00137 #endif // LOGGERBASE_H
00138 //--------------------------
00139 //--------------------------
00140 //--------------------------
00141 

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7