]>
Commit | Line | Data |
---|---|---|
fc455fba | 1 | // @(#) $Id$ |
3495cce2 | 2 | |
3 | #ifndef ALIHLTLOGGING_H | |
4 | #define ALIHLTLOGGING_H | |
1e27470a | 5 | /* This file is property of and copyright by the ALICE HLT Project * |
6 | * ALICE Experiment at CERN, All rights reserved. * | |
3495cce2 | 7 | * See cxx source for full Copyright notice */ |
8 | ||
b22e91eb | 9 | /** @file AliHLTLogging.h |
10 | @author Matthias Richter, Timm Steinbeck | |
11 | @date | |
12 | @brief HLT module logging primitives. | |
13 | */ | |
3495cce2 | 14 | |
15 | #include "AliHLTDataTypes.h" | |
5f1685a0 | 16 | #include "AliHLTStdIncludes.h" |
a1b2201f | 17 | #include "TString.h" |
fc455fba | 18 | #include "TObject.h" |
66043029 | 19 | #include "TArrayC.h" |
3495cce2 | 20 | |
a742f6f8 | 21 | class AliHLTComponentHandler; |
85465857 | 22 | //#define LOG_PREFIX "" // logging prefix, for later extensions |
3495cce2 | 23 | |
db95fec3 | 24 | #define ALILOG_WRAPPER_LIBRARY "libHLTrec.so" |
85465857 | 25 | |
26 | /* the logging macros can be used inside methods of classes which inherit from | |
27 | * AliHLTLogging | |
28 | */ | |
29 | // HLTMessage is not filtered | |
fc455fba | 30 | #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ ) |
85465857 | 31 | |
fc455fba | 32 | // function name |
33 | #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__) | |
34 | #define FUNCTIONNAME() __FUNCTION__ | |
35 | #else | |
36 | #define FUNCTIONNAME() "???" | |
a4a8ef64 | 37 | #endif |
38 | ||
85465857 | 39 | // the following macros are filtered by the Global and Local Log Filter |
fc455fba | 40 | #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) |
1e27470a | 41 | #ifdef __DEBUG |
42 | #define HLTDebug( ... ) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
43 | #else | |
44 | #define HLTDebug( ... ) | |
45 | #endif | |
46 | #define HLTInfo( ... ) if (CheckFilter(kHLTLogInfo)) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
47 | #define HLTWarning( ... ) if (CheckFilter(kHLTLogWarning)) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
48 | #define HLTError( ... ) if (CheckFilter(kHLTLogError)) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
49 | #define HLTFatal( ... ) if (CheckFilter(kHLTLogFatal)) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
b2065764 | 50 | #define HLTImportant( ... ) if (CheckFilter(kHLTLogImportant))LoggingVarargs(kHLTLogImportant,Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) |
85465857 | 51 | |
52 | // helper macro to set the keyword | |
3a7c0444 | 53 | #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey(this, a) |
85465857 | 54 | |
55 | #define HLT_DEFAULT_LOG_KEYWORD "no key" | |
3495cce2 | 56 | |
57 | class AliHLTLogging { | |
58 | public: | |
59 | AliHLTLogging(); | |
85869391 | 60 | AliHLTLogging(const AliHLTLogging&); |
61 | AliHLTLogging& operator=(const AliHLTLogging&); | |
3495cce2 | 62 | virtual ~AliHLTLogging(); |
63 | ||
a742f6f8 | 64 | /** set the default key word |
65 | * the keyword is intended to simplify the use of logging macros | |
66 | */ | |
85465857 | 67 | void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; } |
68 | ||
a742f6f8 | 69 | /** |
70 | * Set a temporary keyword | |
71 | * returns the old key value | |
72 | */ | |
85465857 | 73 | const char* SetKeyword(const char* keyword) |
74 | { | |
75 | const char* currentKeyword=fpCurrentKeyword; | |
76 | fpCurrentKeyword=keyword; | |
77 | return currentKeyword; | |
78 | } | |
79 | ||
a742f6f8 | 80 | /** |
81 | * Get the current keyword | |
82 | */ | |
85869391 | 83 | const char* GetKeyword() const |
85465857 | 84 | { |
85 | if (fpCurrentKeyword) return fpCurrentKeyword; | |
86 | else if (fpDefaultKeyword) return fpDefaultKeyword; | |
87 | return HLT_DEFAULT_LOG_KEYWORD; | |
88 | } | |
3495cce2 | 89 | |
a742f6f8 | 90 | /** |
91 | * Init the AliLogging class for use from external package. | |
92 | * This initializes the logging callback. <br> | |
93 | * Only deployed by external users of the C wrapper interface, not used | |
94 | * when running in AliRoot | |
95 | */ | |
bb16cc41 | 96 | static int Init(AliHLTfctLogging pFun); |
3495cce2 | 97 | |
a742f6f8 | 98 | /** |
99 | * Init the message trap in AliLog. | |
100 | * This initializes the AliLog trap, the AliLog class is the logging | |
101 | * mechanism of AliRoot. The trap can fetch log messages written to | |
102 | * AliLog, components and detector algorithms can use the AliLog | |
103 | * mechanism to be as close as possible to Offline habits. <br> | |
104 | * Only used with external users of the C wrapper interface, not used | |
105 | * when running in AliRoot | |
106 | */ | |
107 | static int InitAliLogTrap(AliHLTComponentHandler* pHandler); | |
108 | ||
db95fec3 | 109 | /** |
110 | * Init the AliRoot logging function. | |
111 | * All log messages are redirected to AliLog when running in AliRoot. | |
112 | * Note: when running in PubSub, AliLog messages are redirected to PubSub, | |
113 | * see AliHLTLogging::InitAliLogTrap | |
114 | */ | |
115 | static int InitAliLogFunc(AliHLTComponentHandler* pHandler); | |
116 | ||
a742f6f8 | 117 | /** |
118 | * Genaral logging function | |
119 | */ | |
8ede8717 | 120 | int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... ); |
3495cce2 | 121 | |
a742f6f8 | 122 | /* |
123 | * Logging function with two origin parameters, used by the log macros | |
124 | */ | |
fc455fba | 125 | int LoggingVarargs(AliHLTComponentLogSeverity severity, |
66043029 | 126 | const char* originClass, const char* originFunc, |
fc455fba | 127 | const char* file, int line, ... ) const; |
3495cce2 | 128 | |
1e27470a | 129 | /** |
130 | * Evaluate the group of the debug message from the class name. | |
131 | * @return 1 if message should be printed | |
132 | */ | |
133 | int CheckGroup(const char* originClass) const; | |
134 | ||
135 | /** | |
136 | * Set the black list of classes. | |
137 | * If the white list is set, debug messages are skipped for | |
138 | * all classes matching one of the regular expressions in the string. | |
139 | */ | |
140 | static int SetBlackList(const char* classnames); | |
141 | ||
142 | /** | |
143 | * Set the white list of classes. | |
144 | * If the white list is set, debug messages are only printed for | |
145 | * classes matching one of the regular expressions in the string. | |
146 | */ | |
147 | static int SetWhiteList(const char* classnames); | |
148 | ||
a742f6f8 | 149 | /** |
150 | * Apply filter | |
151 | * @return 1 if message should pass | |
152 | */ | |
8ede8717 | 153 | int CheckFilter(AliHLTComponentLogSeverity severity) const; |
3495cce2 | 154 | |
a742f6f8 | 155 | /** |
156 | * Set global logging level | |
157 | * logging filter for all objects | |
158 | */ | |
5f5b708b | 159 | static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level); |
160 | ||
a742f6f8 | 161 | /** |
162 | * Get global logging level | |
163 | * logging filter for all objects | |
164 | */ | |
165 | static AliHLTComponentLogSeverity GetGlobalLoggingLevel(); | |
166 | ||
167 | /** | |
168 | * Set local logging level | |
169 | * logging filter for individual object | |
170 | */ | |
dba03d72 | 171 | virtual void SetLocalLoggingLevel(AliHLTComponentLogSeverity level); |
5f5b708b | 172 | |
fc455fba | 173 | /** |
a742f6f8 | 174 | * Get local logging level |
175 | * logging filter for individual object | |
fc455fba | 176 | */ |
a742f6f8 | 177 | AliHLTComponentLogSeverity GetLocalLoggingLevel(); |
3495cce2 | 178 | |
fc455fba | 179 | /** |
a742f6f8 | 180 | * Print message to stdout |
fc455fba | 181 | */ |
a742f6f8 | 182 | static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message); |
fc455fba | 183 | |
184 | /** | |
185 | * Build the log string from format specifier and variadac arguments | |
186 | * @param format format string of printf style | |
187 | * @param ap opened and initialized argument list | |
188 | * @return const char string with the formatted message | |
189 | */ | |
3495cce2 | 190 | static const char* BuildLogString(const char *format, va_list ap); |
191 | ||
66043029 | 192 | /** |
193 | * Get parameter given by the external caller. | |
194 | * This functionality is not yet implemented. It is intended | |
195 | * to pass the parameter pointer given to the component at | |
196 | * initialization back to the caller. | |
197 | */ | |
198 | virtual void* GetParameter() const {return NULL;} | |
fc455fba | 199 | |
200 | /** | |
201 | * Switch logging through AliLog on or off | |
202 | * @param sw 1 = logging through AliLog | |
203 | */ | |
204 | void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);} | |
205 | ||
66043029 | 206 | /** target stream for AliRoot logging methods */ |
207 | static ostringstream fgLogstr; //! transient | |
a742f6f8 | 208 | |
209 | /** | |
210 | * The message function for dynamic use. | |
211 | * In order to avoid dependencies on AliRoot libraries, libHLTbase loads | |
212 | * the library dynamically and looks for the symbol. | |
213 | */ | |
214 | typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity, | |
215 | const char* originClass, | |
216 | const char* originFunc, | |
217 | const char* file, int line, | |
218 | const char* message); | |
219 | ||
220 | /** | |
221 | * The init function of the message callback for dynamic use. | |
222 | * In order to avoid dependencies on AliRoot libraries, libHLTbase loads | |
223 | * the library dynamically and looks for the symbol. | |
224 | */ | |
225 | typedef int (*InitAliDynamicMessageCallback)(); | |
66043029 | 226 | |
3495cce2 | 227 | protected: |
a742f6f8 | 228 | /** the AliRoot logging function */ |
229 | static AliHLTDynamicMessage fgAliLoggingFunc; //! transient | |
3495cce2 | 230 | |
231 | private: | |
fc455fba | 232 | /** the global logging filter */ |
66043029 | 233 | static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above |
fc455fba | 234 | /** the local logging filter for one class */ |
235 | AliHLTComponentLogSeverity fLocalLogFilter; // see above | |
236 | /** logging callback from the framework */ | |
66043029 | 237 | static AliHLTfctLogging fgLoggingFunc; // see above |
fc455fba | 238 | /** default keyword */ |
239 | const char* fpDefaultKeyword; //! transient | |
240 | /** current keyword */ | |
241 | const char* fpCurrentKeyword; //! transient | |
242 | /** switch for logging through AliLog, default on */ | |
243 | static int fgUseAliLog; // see above | |
66043029 | 244 | /** |
245 | * The global logging buffer. | |
246 | * The buffer is created with an initial size and grown dynamically on | |
247 | * demand. | |
248 | */ | |
249 | static TArrayC fgAliHLTLoggingTarget; //! transient | |
250 | ||
251 | /** the maximum size of the buffer */ | |
252 | static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient | |
1e27470a | 253 | |
254 | /** groups of classes not to print debug messages */ | |
255 | static TString fgBlackList; //! transient | |
256 | ||
257 | /** groups of classes not to print debug messages */ | |
258 | static TString fgWhiteList; //! transient | |
a742f6f8 | 259 | |
1e27470a | 260 | ClassDef(AliHLTLogging, 3) |
3495cce2 | 261 | }; |
85465857 | 262 | |
263 | /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro | |
264 | * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class | |
265 | * the object is destroyed automatically when the current scope is left and so the keyword is set | |
266 | * to the original value | |
267 | */ | |
268 | class AliHLTKeyword { | |
269 | public: | |
270 | AliHLTKeyword() | |
85869391 | 271 | : |
272 | fpParent(NULL), | |
273 | fpOriginal(NULL) | |
85465857 | 274 | { |
85465857 | 275 | } |
276 | ||
277 | AliHLTKeyword(AliHLTLogging* parent, const char* keyword) | |
85869391 | 278 | : |
279 | fpParent(parent), | |
280 | fpOriginal(NULL) | |
85465857 | 281 | { |
85465857 | 282 | if (parent) { |
85465857 | 283 | fpOriginal=fpParent->SetKeyword(keyword); |
284 | } | |
285 | } | |
286 | ||
85869391 | 287 | AliHLTKeyword(const AliHLTKeyword& kw) |
288 | : | |
289 | fpParent(kw.fpParent), | |
290 | fpOriginal(kw.fpOriginal) | |
291 | { | |
292 | } | |
293 | ||
294 | AliHLTKeyword& operator=(const AliHLTKeyword& kw) | |
295 | { | |
296 | fpParent=kw.fpParent; | |
297 | fpOriginal=kw.fpOriginal; | |
298 | return *this; | |
299 | } | |
300 | ||
85465857 | 301 | ~AliHLTKeyword() |
302 | { | |
303 | if (fpParent) { | |
304 | fpParent->SetKeyword(fpOriginal); | |
305 | } | |
306 | } | |
307 | ||
308 | private: | |
66043029 | 309 | AliHLTLogging* fpParent; //! transient |
310 | const char* fpOriginal; //! transient | |
85465857 | 311 | }; |
3495cce2 | 312 | #endif |
313 |