Diana Software
QMessage.hh
Go to the documentation of this file.
1 /* Diana Reconstruction program
2  *
3  * Author: MP 11/11/05
4  * $Id: QMessage.hh 76 2006-05-18 15:54:00Z pallas $
5  *
6  * Class QMessage
7  *
8 */
9 
10 #ifndef _Q_MESSAGEHANDLER_H_
11 #define _Q_MESSAGEHANDLER_H_
12 
13 #include <fstream>
14 #include <stdarg.h>
15 #include "QDiana.hh"
16 #include "QMessageDefs.hh"
17 
18 /*
19 enum MsgLevel {
20  NoMsg = 0, // no message
21  DebugMsg = 1, // debugging messages
22  InfoMsg = 2, // information messages
23  WarnMsg = 3, // an anomalous condition that could be fixed
24  ErrorMsg = 4, // " " " " " NOT be fixed
25  PanicMsg = 5, // a fatal error that does not allow to continue
26  NoFilterMsg = 6 // a message that cannot be filtered on logfile
27 };
28 */
29 
31 
33 
34  public:
35  static QMessageHandler *Get();
36  void Init(MsgLevel plevel, MsgLevel llevel, const std::string& logfile);
37  void SetLogVerbosity( MsgLevel logLevel) { log_level = logLevel; }
38  void SetPrintVerbosity( MsgLevel printLevel) { print_level = printLevel; }
39  static inline void Warn(const std::string& sender,const std::string& msg) { QMessageHandler::Get()->Send(WarnMsg,sender,msg); }
40  static inline void Info(const std::string& sender,const std::string& msg) { QMessageHandler::Get()->Send(InfoMsg,sender,msg); }
41  static inline void Debug(const std::string& sender,const std::string& msg) { QMessageHandler::Get()->Send(DebugMsg,sender,msg); }
42  static inline void Error(const std::string& sender,const std::string& msg) { QMessageHandler::Get()->Send(ErrorMsg,sender,msg); }
43  static inline void Panic(const std::string& sender,const std::string& msg) { QMessageHandler::Get()->Send(PanicMsg,sender,msg); }
44 
45  std::ostream& GetLogFile() {return logfile;}
46 
47  virtual ~QMessageHandler() {}
48 
49  void Send(MsgLevel l, const std::string& sender, const std::string& msg );
50 
52 
54 
55  int GetScreenPrintLevel() const { return print_level; }
56 
57  int GetLogPrintLevel() const { return log_level; }
58 
59  private:
62  std::ofstream logfile;
63 
64  // default levels for print and log
67 
68  void SetColor(MsgLevel);
69 
70  // ClassDef(QMessageHandler,0);
71 
72 };
73 
75 
76 #endif
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
MsgLevel
Definition: QMessageDefs.hh:4
@ ErrorMsg
Definition: QMessageDefs.hh:9
@ DebugMsg
Definition: QMessageDefs.hh:6
@ WarnMsg
Definition: QMessageDefs.hh:8
@ PanicMsg
Definition: QMessageDefs.hh:10
@ InfoMsg
Definition: QMessageDefs.hh:7
static void Warn(const std::string &sender, const std::string &msg)
Definition: QMessage.hh:39
void Init(MsgLevel plevel, MsgLevel llevel, const std::string &logfile)
Definition: QMessage.cc:85
static QMessageHandler * Get()
Definition: QMessage.cc:24
std::ofstream logfile
Definition: QMessage.hh:62
void Send(MsgLevel l, const std::string &sender, const std::string &msg)
Definition: QMessage.cc:31
void SetLogVerbosity(MsgLevel logLevel)
Definition: QMessage.hh:37
static void Debug(const std::string &sender, const std::string &msg)
Definition: QMessage.hh:41
void SetScreenPrintLevel(MsgLevel l)
Definition: QMessage.hh:51
MsgLevel print_level
Definition: QMessage.hh:65
void SetPrintVerbosity(MsgLevel printLevel)
Definition: QMessage.hh:38
int GetLogPrintLevel() const
Definition: QMessage.hh:57
virtual ~QMessageHandler()
Definition: QMessage.hh:47
static void Info(const std::string &sender, const std::string &msg)
Definition: QMessage.hh:40
static void Panic(const std::string &sender, const std::string &msg)
Definition: QMessage.hh:43
static void Error(const std::string &sender, const std::string &msg)
Definition: QMessage.hh:42
MsgLevel log_level
Definition: QMessage.hh:66
void SetColor(MsgLevel)
Definition: QMessage.cc:115
int GetScreenPrintLevel() const
Definition: QMessage.hh:55
void SetLogPrintLevel(MsgLevel l)
Definition: QMessage.hh:53
static QMessageHandler * me
Definition: QMessage.hh:61
std::ostream & GetLogFile()
Definition: QMessage.hh:45