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