PSQt/include/Logger.h

Go to the documentation of this file.
00001 #ifndef LOGGER_H
00002 #define LOGGER_H
00003 
00004 //--------------------------
00005 #include "PSQt/LoggerBase.h"
00006 #include <QObject>
00007  
00008 namespace PSQt {
00009 
00010 //--------------------------
00011 
00012 // @addtogroup PSQt Logger
00013 
00014 /**
00015  *  @ingroup PSQt Logger
00016  *
00017  *  @brief Singleton for base class LoggerBase - messaging system
00018  *
00019  *  Connects LoggerBase with GUILogger using method
00020  *  new_record(Record& rec) - callback for re-implementation in subclass,
00021  *  which emits signal with record for each new record above threshold level.
00022  *
00023  *  This software was developed for the LCLS project.  If you use all or 
00024  *  part of it, please give an appropriate acknowledgment.
00025  *
00026  *  @see LoggerBase, GUILogger, GUIMain
00027  *
00028  *  @version $Id: Logger.h 9841 2015-03-26 18:35:44Z dubrovin@SLAC.STANFORD.EDU $
00029  *
00030  *  @author Mikhail Dubrovin
00031  *
00032  *
00033  *  @anchor interface
00034  *  @par<interface> Interface Description
00035  * 
00036  *  @li  Include
00037  *  @code
00038  *  #include "PSQt/Logger.h"
00039  *  @endcode
00040  *
00041  *  @li Instatiation
00042  *  \n
00043  *  Instatiation is not requered, because this class is used as a singleton 
00044  *  with typedef-aliases to the methods like:
00045  *  @code
00046  *  Logger::getLogger()->some_method(...)
00047  *  @endcode
00048  *
00049  *
00050  *  @li Methods with aliases
00051  *  @code
00052  *  MsgInLog(_name_(), INFO, "some message is here"); // send message to the lagger
00053  *  Print("some message is here"); // just print, message is not saved in the logger
00054  *  SetMsgLevel(DEBUG); // change the level of messages for output and saving in file.
00055  *  @endcode
00056  *  @code
00057  *  SaveLog(); // save log in default file with name like: "log-2015-02-09-10:49:36.txt"
00058  *  // OR
00059  *  SaveLog("file-name.txt"); // save log in specified file
00060  *  @endcode
00061  *
00062  *
00063  *  @li Methods without aliases
00064  *  @code
00065  *  Logger::getLogger()->setLevel(DEBUG);
00066  *  LEVEL level = Logger::getLogger()->getLevel();
00067  *  std::string txt_error_msgs = Logger::getLogger()->strRecordsForLevel(ERROR);
00068  *  Logger::getLogger()-> ...
00069  *  @endcode
00070  *
00071  */
00072 
00073 //--------------------------
00074 
00075 class Logger : public QObject, public LoggerBase
00076 {
00077  Q_OBJECT // macro is needed for connection of signals and slots
00078 
00079  public:
00080     static Logger* getLogger(const LEVEL& level=INFO); 
00081  
00082  protected:
00083     virtual void new_record(Record& rec);
00084 
00085  signals:
00086     void signal_new_record(Record&);
00087 
00088  private:
00089     static Logger* p_Logger;
00090  
00091     inline const char* _name_(){return "Logger";}
00092     Logger(const LEVEL& level=INFO); // private constructor! - singleton trick
00093     virtual ~Logger(){}; 
00094 };
00095 
00096 //--------------------------
00097 
00098 #define MsgInLog     Logger::getLogger()->message
00099 #define PrintMsg     Logger::getLogger()->print
00100 #define SetMsgLevel  Logger::getLogger()->setLevel
00101 #define SaveLog      Logger::getLogger()->saveLogInFile
00102 
00103 //--------------------------
00104 
00105 } // namespace PSQt
00106 
00107 #endif // LOGGER_H
00108 //--------------------------
00109 //--------------------------
00110 //--------------------------
00111 

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7