1 | // $Id: EsafMsgDispatcher.hh 2558 2006-03-14 01:10:20Z thea $ |
---|
2 | // Author: M. Pallavicini Sep, 24 2004 |
---|
3 | |
---|
4 | /***************************************************************************** |
---|
5 | * ESAF: Euso Simulation and Analysis Framework * |
---|
6 | * * |
---|
7 | * Id: EsafMsgDispatcher * |
---|
8 | * Package: Base * |
---|
9 | * Coordinator: Marco.Pallavicini * |
---|
10 | * * |
---|
11 | *****************************************************************************/ |
---|
12 | |
---|
13 | #ifndef __ESAFMSGDISPATCHER_HH_ |
---|
14 | #define __ESAFMSGDISPATCHER_HH_ |
---|
15 | |
---|
16 | #include <map> |
---|
17 | #include <string> |
---|
18 | #include <iomanip> |
---|
19 | |
---|
20 | #include "euso.hh" |
---|
21 | #include "EsafConfigurable.hh" |
---|
22 | #include "EsafMsg.hh" |
---|
23 | |
---|
24 | //////////////////////////////////////////////////////////////////////////////// |
---|
25 | // // |
---|
26 | // EsafMsgDispatcher // |
---|
27 | // // |
---|
28 | // Dispatcher writes messages on screen and on logfile // |
---|
29 | // User can set a threshold on the severity of the messages to be displayed // |
---|
30 | // Severity can be also adjusted for specific classes for debugging purposes // |
---|
31 | // // |
---|
32 | //////////////////////////////////////////////////////////////////////////////// |
---|
33 | |
---|
34 | class EsafMsgDispatcher : public EsafConfigurable { |
---|
35 | public: |
---|
36 | virtual ~EsafMsgDispatcher(); |
---|
37 | |
---|
38 | void LoadConfig(); |
---|
39 | // load configuration from config files |
---|
40 | |
---|
41 | void OpenLog( const char* = 0 ); |
---|
42 | // open the log file |
---|
43 | inline void OpenLog( string name ) { OpenLog(name.c_str()); } |
---|
44 | |
---|
45 | static EsafMsgDispatcher* Get(); |
---|
46 | |
---|
47 | void Dispatch( EsafMsg& , Bool_t endline = kTRUE, Bool_t ProcCount = kFALSE); |
---|
48 | |
---|
49 | inline void SetScreenSeverity( EsafMsg::MsgSeverity s ) { fDefaultScreenSeverity = s; } |
---|
50 | inline void SetLogSeverity( EsafMsg::MsgSeverity s ) { fDefaultLogSeverity = s; } |
---|
51 | |
---|
52 | inline EsafMsg::MsgSeverity GetScreenSeverity() { return fDefaultScreenSeverity; } |
---|
53 | inline EsafMsg::MsgSeverity GetLogSeverity() { return fDefaultLogSeverity; } |
---|
54 | |
---|
55 | EsafConfigClass(General,EsafMsgDispatcher) |
---|
56 | |
---|
57 | private: |
---|
58 | EsafMsgDispatcher(); |
---|
59 | static EsafMsgDispatcher* fMe; |
---|
60 | Int_t fHeaderLenght; |
---|
61 | Bool_t fIsScreenFlushed; |
---|
62 | Bool_t fIsLogFlushed; |
---|
63 | Bool_t fUseColors; |
---|
64 | |
---|
65 | static const char *const kEsc; |
---|
66 | static const char *const kReset; |
---|
67 | static const char *const kRed; |
---|
68 | static const char *const kGreen; |
---|
69 | static const char *const kYellow; |
---|
70 | static const char *const kBlue; |
---|
71 | |
---|
72 | static const char *const kMagenta; |
---|
73 | static const char *const kCyan; |
---|
74 | static const char *const kWhite; |
---|
75 | static const char *const kBlack; |
---|
76 | |
---|
77 | static const char *const kBckRed; |
---|
78 | static const char *const kBckGreen; |
---|
79 | static const char *const kBckYellow; |
---|
80 | static const char *const kBckBlue; |
---|
81 | static const char *const kBckMagenta; |
---|
82 | static const char *const kBckCyan; |
---|
83 | static const char *const kBckWhite; |
---|
84 | static const char *const kBckBlack; |
---|
85 | |
---|
86 | static const char *const kUnderline; |
---|
87 | static const char *const kBlink; |
---|
88 | static const char *const kBright; |
---|
89 | static const char *const kDark; |
---|
90 | |
---|
91 | static const char *fgColors[]; |
---|
92 | |
---|
93 | EsafMsg::MsgSeverity fDefaultLogSeverity; // default severity level for log file |
---|
94 | EsafMsg::MsgSeverity fDefaultScreenSeverity; // default severity level for screen |
---|
95 | string fLogFileName; // log file name |
---|
96 | map<string,EsafMsg::MsgSeverity> fUserMap; // map of user defined target dependent severities |
---|
97 | |
---|
98 | ofstream fLogFile; |
---|
99 | EsafMsg fException; |
---|
100 | |
---|
101 | ClassDef(EsafMsgDispatcher,0) |
---|
102 | |
---|
103 | }; |
---|
104 | |
---|
105 | #endif /* __ESAFMSGDISPATCHER_HH_ */ |
---|
106 | |
---|