]>
Commit | Line | Data |
---|---|---|
6ab674bd | 1 | #ifndef ALILOG_H |
2 | #define ALILOG_H | |
3 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
4 | * See cxx source for full Copyright notice */ | |
5 | ||
6 | /* $Id$ */ | |
7 | ||
8 | /// | |
9 | /// class for logging debug, info and error messages | |
10 | /// | |
11 | ||
12 | #include <TObject.h> | |
13 | #include <TObjArray.h> | |
14 | #include <TString.h> | |
15 | ||
16 | ||
17 | class AliLog: public TObject { | |
18 | public: | |
19 | AliLog(); | |
20 | virtual ~AliLog(); | |
21 | static AliLog* Instance() {return fgInstance;} | |
22 | ||
23 | enum EType {kFatal = 0, kError, kWarning, kInfo, kDebug, kMaxType}; | |
24 | ||
25 | static void EnableDebug(Bool_t enabled); | |
26 | static void SetGlobalLogLevel(EType type); | |
27 | static Int_t GetGlobalLogLevel(); | |
28 | static void SetGlobalDebugLevel(Int_t level); | |
29 | static Int_t GetGlobalDebugLevel(); | |
30 | static void SetModuleDebugLevel(const char* module, Int_t level); | |
31 | static void ClearModuleDebugLevel(const char* module); | |
32 | static void SetClassDebugLevel(const char* className, Int_t level); | |
33 | static void ClearClassDebugLevel(const char* className); | |
34 | ||
35 | static void SetStandardOutput(); | |
36 | static void SetStandardOutput(EType type); | |
37 | static void SetErrorOutput(); | |
38 | static void SetErrorOutput(EType type); | |
39 | static void SetFileOutput(const char* fileName); | |
40 | static void SetFileOutput(EType type, const char* fileName); | |
41 | static void Flush(); | |
42 | ||
43 | static void SetHandleRootMessages(Bool_t on); | |
44 | ||
45 | static void SetPrintType(Bool_t on); | |
46 | static void SetPrintType(EType type, Bool_t on); | |
47 | static void SetPrintModule(Bool_t on); | |
48 | static void SetPrintModule(EType type, Bool_t on); | |
49 | static void SetPrintScope(Bool_t on); | |
50 | static void SetPrintScope(EType type, Bool_t on); | |
51 | static void SetPrintLocation(Bool_t on); | |
52 | static void SetPrintLocation(EType type, Bool_t on); | |
53 | ||
45fa0297 | 54 | static void SetPrintRepetitions(Bool_t on); |
55 | ||
6ab674bd | 56 | static void Write(const char* name, Int_t option = 0); |
57 | ||
58 | // the following public methods are used by the preprocessor macros | |
59 | // and should not be called directly | |
20848f77 | 60 | static Bool_t IsDebugEnabled() {return fgDebugEnabled;} |
6ab674bd | 61 | static Int_t GetDebugLevel(const char* module, const char* className); |
62 | static void Message(UInt_t level, const char* message, | |
63 | const char* module, const char* className, | |
64 | const char* function, const char* file, Int_t line); | |
65 | static void Debug(UInt_t level, const char* message, | |
66 | const char* module, const char* className, | |
67 | const char* function, const char* file, Int_t line); | |
68 | ||
eeb769e2 | 69 | static Int_t RedirectStdoutTo(EType type, UInt_t level, const char* module, |
70 | const char* className, const char* function, | |
71 | const char* file, Int_t line, Bool_t print); | |
72 | static Int_t RedirectStderrTo(EType type, UInt_t level, const char* module, | |
73 | const char* className, const char* function, | |
74 | const char* file, Int_t line, Bool_t print); | |
75 | static void RestoreStdout(Int_t original); | |
76 | static void RestoreStderr(Int_t original); | |
77 | ||
78 | static ostream& Stream(EType type, UInt_t level, | |
79 | const char* module, const char* className, | |
80 | const char* function, const char* file, Int_t line); | |
81 | ||
6ab674bd | 82 | private: |
83 | AliLog(const AliLog& log); | |
84 | AliLog& operator = (const AliLog& log); | |
85 | ||
eeb769e2 | 86 | void ReadEnvSettings(); |
87 | ||
6ab674bd | 88 | static void RootErrorHandler(Int_t level, Bool_t abort, |
89 | const char* location, const char* message); | |
90 | ||
91 | void CloseFile(Int_t type); | |
92 | FILE* GetOutputStream(Int_t type); | |
93 | ||
94 | UInt_t GetLogLevel(const char* module, const char* className) const; | |
eeb769e2 | 95 | void PrintMessage(UInt_t type, const char* message, |
96 | const char* module, const char* className, | |
97 | const char* function, | |
98 | const char* file, Int_t line); | |
45fa0297 | 99 | void PrintRepetitions(); |
eeb769e2 | 100 | |
101 | Int_t RedirectTo(FILE* stream, EType type, UInt_t level, | |
102 | const char* module, const char* className, | |
103 | const char* function, | |
104 | const char* file, Int_t line, Bool_t print); | |
105 | ||
106 | ostream& GetStream(EType type, UInt_t level, | |
107 | const char* module, const char* className, | |
108 | const char* function, const char* file, Int_t line); | |
6ab674bd | 109 | |
110 | enum {kDebugOffset = kDebug-1}; | |
111 | ||
112 | static AliLog* fgInstance; //! pointer to current instance | |
113 | ||
114 | static Bool_t fgDebugEnabled; // flag for debug en-/disabling | |
115 | ||
116 | UInt_t fGlobalLogLevel; // global logging level | |
117 | TObjArray fModuleDebugLevels; // debug levels for modules | |
118 | TObjArray fClassDebugLevels; // debug levels for classes | |
119 | ||
120 | Int_t fOutputTypes[kMaxType]; // types of output streams | |
121 | TString fFileNames[kMaxType]; // file names | |
122 | FILE* fOutputFiles[kMaxType]; //! log output files | |
eeb769e2 | 123 | ofstream* fOutputStreams[kMaxType]; //! log output streams |
6ab674bd | 124 | |
125 | Bool_t fPrintType[kMaxType]; // print type on/off | |
126 | Bool_t fPrintModule[kMaxType]; // print module on/off | |
127 | Bool_t fPrintScope[kMaxType]; // print scope/class name on/off | |
128 | Bool_t fPrintLocation[kMaxType]; // print file and line on/off | |
129 | ||
45fa0297 | 130 | Bool_t fPrintRepetitions; // print number of repetitions instead of repeated message on/off |
131 | ||
132 | Int_t fRepetitions; //! counter of repetitions | |
133 | UInt_t fLastType; //! type of last message | |
134 | TString fLastMessage; //! last message | |
135 | TString fLastModule; //! module name of last message | |
136 | TString fLastClassName; //! class name of last message | |
137 | TString fLastFunction; //! function name of last message | |
138 | TString fLastFile; //! file name of last message | |
139 | Int_t fLastLine; //! line number of last message | |
140 | ||
6ab674bd | 141 | ClassDef(AliLog, 1) // class for logging debug, info and error messages |
142 | }; | |
143 | ||
eeb769e2 | 144 | |
145 | // module name | |
146 | #ifdef __MODULE__ | |
147 | #define MODULENAME() __MODULE__ | |
148 | #else | |
149 | #define MODULENAME() "NoModule" | |
cd676389 | 150 | #endif |
eeb769e2 | 151 | |
152 | // function name | |
153 | #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__) | |
154 | #define FUNCTIONNAME() __FUNCTION__ | |
92154bc0 | 155 | // #elif defined(__HP_aCC) || defined(__alpha) || defined(__DECCXX) |
156 | // #define FUNCTIONNAME() __FUNC__ | |
eeb769e2 | 157 | #else |
158 | #define FUNCTIONNAME() "???" | |
cd676389 | 159 | #endif |
6ab674bd | 160 | |
eeb769e2 | 161 | // redirection |
162 | #define REDIRECTSTDOUT(type, level, scope, whatever) {Int_t originalStdout = AliLog::RedirectStdoutTo(type, level, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__, kFALSE); whatever; AliLog::RestoreStdout(originalStdout);} | |
163 | #define REDIRECTSTDERR(type, level, scope, whatever) {Int_t originalStderr = AliLog::RedirectStderrTo(type, level, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__, kFALSE); whatever; AliLog::RestoreStderr(originalStderr);} | |
164 | #define REDIRECTSTDOUTANDSTDERR(type, level, scope, whatever) {Int_t originalStdout = AliLog::RedirectStdoutTo(type, level, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__, kFALSE); Int_t originalStderr = AliLog::RedirectStderrTo(type, level, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__, kFALSE); whatever; AliLog::RestoreStderr(originalStderr); AliLog::RestoreStdout(originalStdout);} | |
165 | ||
166 | ||
167 | // debug level | |
6ab674bd | 168 | #ifdef LOG_NO_DEBUG |
169 | #define AliDebugLevel() -1 | |
170 | #define AliDebugLevelClass() -1 | |
171 | #define AliDebugLevelGeneral(scope) -1 | |
172 | #else | |
eeb769e2 | 173 | #define AliDebugLevel() ((AliLog::IsDebugEnabled()) ? AliLog::GetDebugLevel(MODULENAME(), ClassName()) : -1) |
174 | #define AliDebugLevelClass() ((AliLog::IsDebugEnabled()) ? AliLog::GetDebugLevel(MODULENAME(), Class()->GetName()) : -1) | |
175 | #define AliDebugLevelGeneral(scope) ((AliLog::IsDebugEnabled()) ? AliLog::GetDebugLevel(MODULENAME(), scope) : -1) | |
6ab674bd | 176 | #endif |
177 | ||
eeb769e2 | 178 | // debug messages |
6ab674bd | 179 | #ifdef LOG_NO_DEBUG |
180 | #define AliDebug(level, message) | |
181 | #define AliDebugClass(level, message) | |
182 | #define AliDebugGeneral(scope, level, message) | |
183 | #else | |
eeb769e2 | 184 | #define AliDebug(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);} |
185 | #define AliDebugClass(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
186 | #define AliDebugGeneral(scope, level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);} | |
6ab674bd | 187 | #endif |
188 | ||
eeb769e2 | 189 | // redirection to debug |
190 | #define StdoutToAliDebug(level, whatever) REDIRECTSTDOUT(AliLog::kDebug, level, ClassName(), whatever) | |
191 | #define StderrToAliDebug(level, whatever) REDIRECTSTDERR(AliLog::kDebug, level, ClassName(), whatever) | |
192 | #define ToAliDebug(level, whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kDebug, level, ClassName(), whatever) | |
193 | #define StdoutToAliDebugClass(level, whatever) REDIRECTSTDOUT(AliLog::kDebug, level, Class()->GetName(), whatever) | |
194 | #define StderrToAliDebugClass(level, whatever) REDIRECTSTDERR(AliLog::kDebug, level, Class()->GetName(), whatever) | |
195 | #define ToAliDebugClass(level, whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kDebug, level, Class()->GetName(), whatever) | |
196 | #define StdoutToAliDebugGeneral(scope, level, whatever) REDIRECTSTDOUT(AliLog::kDebug, level, scope, whatever) | |
197 | #define StderrToAliDebugGeneral(scope, level, whatever) REDIRECTSTDERR(AliLog::kDebug, level, scope, whatever) | |
198 | #define ToAliDebugGeneral(scope, level, whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kDebug, level, scope, whatever) | |
199 | ||
200 | // debug stream objects | |
201 | #define AliDebugStream(level) AliLog::Stream(AliLog::kDebug, level, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
202 | #define AliDebugClassStream(level) AliLog::Stream(AliLog::kDebug, level, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
203 | #define AliDebugGeneralStream(scope, level) AliLog::Stream(AliLog::kDebug, level, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__) | |
204 | ||
205 | ||
206 | // info messages | |
6ab674bd | 207 | #ifdef LOG_NO_INFO |
208 | #define AliInfo(message) | |
209 | #define AliInfoClass(message) | |
210 | #define AliInfoGeneral(scope, message) | |
211 | #else | |
eeb769e2 | 212 | #define AliInfo(message) {AliLog::Message(AliLog::kInfo, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);} |
213 | #define AliInfoClass(message) {AliLog::Message(AliLog::kInfo, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
214 | #define AliInfoGeneral(scope, message) {AliLog::Message(AliLog::kInfo, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);} | |
6ab674bd | 215 | #endif |
216 | ||
eeb769e2 | 217 | // redirection to info |
218 | #define StdoutToAliInfo(whatever) REDIRECTSTDOUT(AliLog::kInfo, 0, ClassName(), whatever) | |
219 | #define StderrToAliInfo(whatever) REDIRECTSTDERR(AliLog::kInfo, 0, ClassName(), whatever) | |
220 | #define ToAliInfo(whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kInfo, 0, ClassName(), whatever) | |
221 | #define StdoutToAliInfoClass(whatever) REDIRECTSTDOUT(AliLog::kInfo, 0, Class()->GetName(), whatever) | |
222 | #define StderrToAliInfoClass(whatever) REDIRECTSTDERR(AliLog::kInfo, 0, Class()->GetName(), whatever) | |
223 | #define ToAliInfoClass(whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kInfo, 0, Class()->GetName(), whatever) | |
224 | #define StdoutToAliInfoGeneral(scope, whatever) REDIRECTSTDOUT(AliLog::kInfo, 0, scope, whatever) | |
225 | #define StderrToAliInfoGeneral(scope, whatever) REDIRECTSTDERR(AliLog::kInfo, 0, scope, whatever) | |
226 | #define ToAliInfoGeneral(scope, whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kInfo, 0, scope, whatever) | |
227 | ||
228 | // info stream objects | |
229 | #define AliInfoStream() AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
230 | #define AliInfoClassStream() AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
231 | #define AliInfoGeneralStream(scope) AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__) | |
232 | ||
233 | ||
234 | // warning messages | |
6ab674bd | 235 | #ifdef LOG_NO_WARNING |
236 | #define AliWarning(message) | |
237 | #define AliWarningClass(message) | |
238 | #define AliWarningGeneral(scope, message) | |
239 | #else | |
eeb769e2 | 240 | #define AliWarning(message) {AliLog::Message(AliLog::kWarning, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);} |
241 | #define AliWarningClass(message) {AliLog::Message(AliLog::kWarning, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
242 | #define AliWarningGeneral(scope, message) {AliLog::Message(AliLog::kWarning, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);} | |
6ab674bd | 243 | #endif |
244 | ||
eeb769e2 | 245 | // redirection to warning |
246 | #define StdoutToAliWarning(whatever) REDIRECTSTDOUT(AliLog::kWarning, 0, ClassName(), whatever) | |
247 | #define StderrToAliWarning(whatever) REDIRECTSTDERR(AliLog::kWarning, 0, ClassName(), whatever) | |
248 | #define ToAliWarning(whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kWarning, 0, ClassName(), whatever) | |
249 | #define StdoutToAliWarningClass(whatever) REDIRECTSTDOUT(AliLog::kWarning, 0, Class()->GetName(), whatever) | |
250 | #define StderrToAliWarningClass(whatever) REDIRECTSTDERR(AliLog::kWarning, 0, Class()->GetName(), whatever) | |
251 | #define ToAliWarningClass(whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kWarning, 0, Class()->GetName(), whatever) | |
252 | #define StdoutToAliWarningGeneral(scope, whatever) REDIRECTSTDOUT(AliLog::kWarning, 0, scope, whatever) | |
253 | #define StderrToAliWarningGeneral(scope, whatever) REDIRECTSTDERR(AliLog::kWarning, 0, scope, whatever) | |
254 | #define ToAliWarningGeneral(scope, whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kWarning, 0, scope, whatever) | |
255 | ||
256 | // warning stream objects | |
257 | #define AliWarningStream() AliLog::Stream(AliLog::kWarning, 0, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
258 | #define AliWarningClassStream() AliLog::Stream(AliLog::kWarning, 0, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
259 | #define AliWarningGeneralStream(scope) AliLog::Stream(AliLog::kWarning, 0, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__) | |
260 | ||
261 | ||
262 | // error messages | |
263 | #define AliError(message) {AliLog::Message(AliLog::kError, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
264 | #define AliErrorClass(message) {AliLog::Message(AliLog::kError, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
265 | #define AliErrorGeneral(scope, message) {AliLog::Message(AliLog::kError, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);} | |
266 | ||
267 | // redirection to error | |
268 | #define StdoutToAliError(whatever) REDIRECTSTDOUT(AliLog::kError, 0, ClassName(), whatever) | |
269 | #define StderrToAliError(whatever) REDIRECTSTDERR(AliLog::kError, 0, ClassName(), whatever) | |
270 | #define ToAliError(whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kError, 0, ClassName(), whatever) | |
271 | #define StdoutToAliErrorClass(whatever) REDIRECTSTDOUT(AliLog::kError, 0, Class()->GetName(), whatever) | |
272 | #define StderrToAliErrorClass(whatever) REDIRECTSTDERR(AliLog::kError, 0, Class()->GetName(), whatever) | |
273 | #define ToAliErrorClass(whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kError, 0, Class()->GetName(), whatever) | |
274 | #define StdoutToAliErrorGeneral(scope, whatever) REDIRECTSTDOUT(AliLog::kError, 0, scope, whatever) | |
275 | #define StderrToAliErrorGeneral(scope, whatever) REDIRECTSTDERR(AliLog::kError, 0, scope, whatever) | |
276 | #define ToAliErrorGeneral(scope, whatever) REDIRECTSTDOUTANDSTDERR(AliLog::kError, 0, scope, whatever) | |
277 | ||
278 | // error stream objects | |
279 | #define AliErrorStream() AliLog::Stream(AliLog::kError, 0, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
280 | #define AliErrorClassStream() AliLog::Stream(AliLog::kError, 0, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__) | |
281 | #define AliErrorGeneralStream(scope) AliLog::Stream(AliLog::kError, 0, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__) | |
282 | ||
6ab674bd | 283 | |
eeb769e2 | 284 | // fatal messages |
285 | #define AliFatal(message) {AliLog::Message(AliLog::kFatal, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
286 | #define AliFatalClass(message) {AliLog::Message(AliLog::kFatal, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);} | |
287 | #define AliFatalGeneral(scope, message) {AliLog::Message(AliLog::kFatal, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);} | |
6ab674bd | 288 | |
289 | #endif |