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