]>
Commit | Line | Data |
---|---|---|
fc455fba | 1 | // @(#) $Id$ |
3495cce2 | 2 | |
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
3495cce2 | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * for The ALICE HLT Project. * | |
3495cce2 | 9 | * * |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
b22e91eb | 19 | /** @file AliHLTLogging.cxx |
20 | @author Matthias Richter, Timm Steinbeck | |
21 | @date | |
22 | @brief Implementation of HLT logging primitives. | |
23 | */ | |
3495cce2 | 24 | |
0c0c9d99 | 25 | #if __GNUC__>= 3 |
3495cce2 | 26 | using namespace std; |
27 | #endif | |
28 | ||
85869391 | 29 | #include "AliHLTStdIncludes.h" |
3495cce2 | 30 | #include "AliHLTLogging.h" |
a742f6f8 | 31 | #include "AliHLTComponentHandler.h" |
3cde846d | 32 | #include "TString.h" |
fc455fba | 33 | #include "Varargs.h" |
34 | #include <string> | |
35 | #include <sstream> | |
36 | #include <iostream> | |
37 | ||
b22e91eb | 38 | /** ROOT macro for the implementation of ROOT specific class methods */ |
a742f6f8 | 39 | ClassImp(AliHLTLogging); |
3495cce2 | 40 | |
3495cce2 | 41 | AliHLTLogging::AliHLTLogging() |
85869391 | 42 | : |
85869391 | 43 | //fLocalLogFilter(kHLTLogDefault), |
53feaef5 | 44 | fLocalLogFilter(kHLTLogAll), |
45 | fpDefaultKeyword(NULL), | |
46 | fpCurrentKeyword(NULL) | |
3495cce2 | 47 | { |
5f5b708b | 48 | // see header file for class documentation |
49 | // or | |
50 | // refer to README to build package | |
51 | // or | |
52 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
85869391 | 53 | } |
54 | ||
55 | AliHLTLogging::AliHLTLogging(const AliHLTLogging&) | |
56 | : | |
53feaef5 | 57 | fLocalLogFilter(kHLTLogAll), |
85869391 | 58 | fpDefaultKeyword(NULL), |
53feaef5 | 59 | fpCurrentKeyword(NULL) |
85869391 | 60 | { |
5f5b708b | 61 | // see header file for class documentation |
85869391 | 62 | HLTFatal("copy constructor untested"); |
63 | } | |
64 | ||
65 | AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&) | |
66 | { | |
5f5b708b | 67 | // see header file for class documentation |
85869391 | 68 | HLTFatal("assignment operator untested"); |
69 | return *this; | |
3495cce2 | 70 | } |
71 | ||
66043029 | 72 | ostringstream AliHLTLogging::fgLogstr; |
73 | AliHLTComponentLogSeverity AliHLTLogging::fgGlobalLogFilter=kHLTLogAll; | |
74 | AliHLTfctLogging AliHLTLogging::fgLoggingFunc=NULL; | |
a742f6f8 | 75 | AliHLTLogging::AliHLTDynamicMessage AliHLTLogging::fgAliLoggingFunc=NULL; |
fc455fba | 76 | int AliHLTLogging::fgUseAliLog=1; |
3495cce2 | 77 | |
1e27470a | 78 | TString AliHLTLogging::fgBlackList=""; |
79 | TString AliHLTLogging::fgWhiteList=""; | |
80 | ||
3495cce2 | 81 | AliHLTLogging::~AliHLTLogging() |
82 | { | |
5f5b708b | 83 | // see header file for class documentation |
3495cce2 | 84 | } |
85 | ||
a742f6f8 | 86 | // the array will be grown dynamically, this is just an initial size |
66043029 | 87 | TArrayC AliHLTLogging::fgAliHLTLoggingTarget(200); |
a742f6f8 | 88 | // the maximum size of the array |
66043029 | 89 | const int AliHLTLogging::fgkALIHLTLOGGINGMAXBUFFERSIZE=10000; |
90 | ||
bb16cc41 | 91 | int AliHLTLogging::Init(AliHLTfctLogging pFun) |
fa274626 | 92 | { |
5f5b708b | 93 | // see header file for class documentation |
66043029 | 94 | if (fgLoggingFunc!=NULL && fgLoggingFunc!=pFun) { |
95 | (*fgLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function"); | |
bb16cc41 | 96 | } |
66043029 | 97 | fgLoggingFunc=pFun; |
fc455fba | 98 | |
bb16cc41 | 99 | return 0; |
100 | } | |
101 | ||
a742f6f8 | 102 | int AliHLTLogging::InitAliLogTrap(AliHLTComponentHandler* pHandler) |
103 | { | |
104 | // see header file for class documentation | |
db95fec3 | 105 | // init the AliRoot logging trap |
106 | // AliLog messages are redirected to PubSub, | |
a742f6f8 | 107 | int iResult=0; |
108 | if (pHandler) { | |
db95fec3 | 109 | // set temporary loglevel of component handler |
a742f6f8 | 110 | AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel(); |
111 | pHandler->SetLocalLoggingLevel(kHLTLogError); | |
db95fec3 | 112 | |
113 | // load library containing AliRoot dependencies and initialization handler | |
114 | pHandler->LoadLibrary(ALILOG_WRAPPER_LIBRARY, 0/* do not activate agents */); | |
115 | ||
116 | // restore loglevel | |
a742f6f8 | 117 | pHandler->SetLocalLoggingLevel(loglevel); |
db95fec3 | 118 | |
119 | // find the symbol | |
120 | InitAliDynamicMessageCallback pFunc=(InitAliDynamicMessageCallback)pHandler->FindSymbol(ALILOG_WRAPPER_LIBRARY, "InitAliDynamicMessageCallback"); | |
a742f6f8 | 121 | if (pFunc) { |
122 | iResult=(*pFunc)(); | |
123 | } else { | |
124 | Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogTrap", "init logging", | |
125 | "can not initialize AliLog callback"); | |
126 | iResult=-ENOSYS; | |
127 | } | |
128 | } else { | |
129 | iResult=-EINVAL; | |
130 | } | |
131 | ||
132 | return iResult; | |
133 | } | |
134 | ||
db95fec3 | 135 | int AliHLTLogging::InitAliLogFunc(AliHLTComponentHandler* pHandler) |
136 | { | |
137 | // see header file for class documentation | |
138 | int iResult=0; | |
139 | if (pHandler) { | |
140 | // set temporary loglevel of component handler | |
141 | AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel(); | |
142 | pHandler->SetLocalLoggingLevel(kHLTLogError); | |
143 | ||
144 | // load library containing AliRoot dependencies and initialization handler | |
145 | pHandler->LoadLibrary(ALILOG_WRAPPER_LIBRARY, 0/* do not activate agents */); | |
146 | ||
147 | // restore loglevel | |
148 | pHandler->SetLocalLoggingLevel(loglevel); | |
149 | ||
150 | // find the symbol | |
151 | fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)pHandler->FindSymbol(ALILOG_WRAPPER_LIBRARY, "AliDynamicMessage"); | |
152 | if (fgAliLoggingFunc==NULL) { | |
153 | Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogFunc", "init logging", | |
154 | "symbol lookp failure: can not find AliDynamicMessage, switching to HLT logging system"); | |
155 | iResult=-ENOSYS; | |
156 | } | |
157 | } else { | |
158 | iResult=-EINVAL; | |
159 | } | |
160 | ||
161 | return iResult; | |
162 | } | |
163 | ||
fc455fba | 164 | int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity, |
165 | const char* origin, const char* keyword, | |
166 | const char* message) | |
5f5b708b | 167 | { |
168 | // see header file for class documentation | |
3495cce2 | 169 | int iResult=0; |
53feaef5 | 170 | if (param==NULL) { |
171 | // this is currently just to get rid of the warning "unused parameter" | |
172 | } | |
fc455fba | 173 | |
3495cce2 | 174 | const char* strSeverity=""; |
175 | switch (severity) { | |
176 | case kHLTLogBenchmark: | |
177 | strSeverity="benchmark"; | |
178 | break; | |
179 | case kHLTLogDebug: | |
180 | strSeverity="debug"; | |
181 | break; | |
182 | case kHLTLogInfo: | |
183 | strSeverity="info"; | |
184 | break; | |
185 | case kHLTLogWarning: | |
186 | strSeverity="warning"; | |
187 | break; | |
188 | case kHLTLogError: | |
189 | strSeverity="error"; | |
190 | break; | |
191 | case kHLTLogFatal: | |
192 | strSeverity="fatal"; | |
193 | break; | |
194 | default: | |
195 | break; | |
196 | } | |
3cde846d | 197 | TString out="HLT Log "; |
198 | out+=strSeverity; | |
d54f579e | 199 | if (origin && origin[0]!=0) {out+=": <"; out+=origin; out+="> ";} |
3cde846d | 200 | out+=" "; out+=message; |
201 | if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) { | |
202 | out+=" ("; out+=keyword; out +=")"; | |
203 | } | |
204 | cout << out.Data() << endl; | |
3495cce2 | 205 | return iResult; |
206 | } | |
207 | ||
a742f6f8 | 208 | #if 0 |
fc455fba | 209 | int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity, |
66043029 | 210 | const char* originClass, const char* originFunc, |
fc455fba | 211 | const char* file, int line, const char* message) |
5f5b708b | 212 | { |
213 | // see header file for class documentation | |
3495cce2 | 214 | |
fc455fba | 215 | switch (severity) { |
216 | case kHLTLogBenchmark: | |
66043029 | 217 | AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 218 | break; |
219 | case kHLTLogDebug: | |
66043029 | 220 | AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 221 | break; |
222 | case kHLTLogInfo: | |
66043029 | 223 | AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 224 | break; |
225 | case kHLTLogWarning: | |
66043029 | 226 | AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 227 | break; |
228 | case kHLTLogError: | |
66043029 | 229 | AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 230 | break; |
231 | case kHLTLogFatal: | |
66043029 | 232 | AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 233 | break; |
234 | default: | |
235 | break; | |
236 | } | |
237 | return 0; | |
238 | } | |
85465857 | 239 | #endif |
fc455fba | 240 | |
241 | const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) | |
242 | { | |
243 | // see header file for class documentation | |
244 | ||
245 | int iResult=0; | |
a59b461e | 246 | #ifdef R__VA_COPY |
fc455fba | 247 | va_list bap; |
248 | R__VA_COPY(bap, ap); | |
a59b461e | 249 | #endif //R__VA_COPY |
fc455fba | 250 | |
251 | // take the first argument from the list as format string if no | |
252 | // format was given | |
253 | const char* fmt = format; | |
254 | if (fmt==NULL) fmt=va_arg(ap, const char*); | |
255 | ||
66043029 | 256 | fgAliHLTLoggingTarget[0]=0; |
fc455fba | 257 | while (fmt!=NULL) { |
66043029 | 258 | iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray(), fgAliHLTLoggingTarget.GetSize(), fmt, ap); |
fc455fba | 259 | if (iResult==-1) |
260 | // for compatibility with older version of vsnprintf | |
66043029 | 261 | iResult=fgAliHLTLoggingTarget.GetSize()*2; |
262 | else if (iResult<fgAliHLTLoggingTarget.GetSize()) | |
fc455fba | 263 | break; |
264 | ||
265 | // terminate if buffer is already at the limit | |
66043029 | 266 | if (fgAliHLTLoggingTarget.GetSize()>=fgkALIHLTLOGGINGMAXBUFFERSIZE) |
a59b461e | 267 | { |
66043029 | 268 | fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0; |
fc455fba | 269 | break; |
3495cce2 | 270 | } |
fc455fba | 271 | |
272 | // check limitation and grow the buffer | |
66043029 | 273 | if (iResult>fgkALIHLTLOGGINGMAXBUFFERSIZE) iResult=fgkALIHLTLOGGINGMAXBUFFERSIZE; |
274 | fgAliHLTLoggingTarget.Set(iResult+1); | |
fc455fba | 275 | |
276 | // copy the original list and skip the first argument if this was the format string | |
a59b461e | 277 | #ifdef R__VA_COPY |
fc455fba | 278 | va_end(ap); |
279 | R__VA_COPY(ap, bap); | |
a59b461e | 280 | #else |
66043029 | 281 | fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0; |
a59b461e | 282 | break; |
283 | #endif //R__VA_COPY | |
fc455fba | 284 | if (format==NULL) va_arg(ap, const char*); |
285 | } | |
a59b461e | 286 | #ifdef R__VA_COPY |
fc455fba | 287 | va_end(bap); |
a59b461e | 288 | #endif //R__VA_COPY |
fc455fba | 289 | |
66043029 | 290 | return fgAliHLTLoggingTarget.GetArray(); |
3495cce2 | 291 | } |
292 | ||
fc455fba | 293 | int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, |
294 | const char* origin, const char* keyword, | |
295 | const char* format, ... ) | |
5f5b708b | 296 | { |
297 | // see header file for class documentation | |
85465857 | 298 | int iResult=CheckFilter(severity); |
299 | if (iResult>0) { | |
300 | va_list args; | |
301 | va_start(args, format); | |
66043029 | 302 | if (fgLoggingFunc) { |
303 | iResult = (*fgLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); | |
85465857 | 304 | } else { |
a742f6f8 | 305 | if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL) |
306 | iResult=(*fgAliLoggingFunc)(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args )); | |
fc455fba | 307 | else |
fc455fba | 308 | iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); |
85465857 | 309 | } |
fc455fba | 310 | va_end(args); |
3495cce2 | 311 | } |
85465857 | 312 | return iResult; |
3495cce2 | 313 | } |
314 | ||
fc455fba | 315 | int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity, |
66043029 | 316 | const char* originClass, const char* originFunc, |
fc455fba | 317 | const char* file, int line, ... ) const |
3495cce2 | 318 | { |
5f5b708b | 319 | // see header file for class documentation |
320 | ||
fc455fba | 321 | if (file==NULL && line==0) { |
322 | // this is currently just to get rid of the warning "unused parameter" | |
323 | } | |
1e27470a | 324 | int iResult=1; //CheckFilter(severity); // check moved to makro |
85465857 | 325 | if (iResult>0) { |
85465857 | 326 | const char* separator=""; |
fc455fba | 327 | TString origin; |
66043029 | 328 | if (originClass) { |
329 | origin+=originClass; | |
85465857 | 330 | separator="::"; |
3495cce2 | 331 | } |
66043029 | 332 | if (originFunc) { |
fc455fba | 333 | origin+=separator; |
66043029 | 334 | origin+=originFunc; |
3495cce2 | 335 | } |
85465857 | 336 | va_list args; |
fc455fba | 337 | va_start(args, line); |
85465857 | 338 | |
66043029 | 339 | if (fgLoggingFunc) { |
340 | iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args )); | |
85465857 | 341 | } else { |
a742f6f8 | 342 | if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL) |
343 | iResult=(*fgAliLoggingFunc)(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args )); | |
fc455fba | 344 | else |
fc455fba | 345 | iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args )); |
85465857 | 346 | } |
347 | va_end(args); | |
3495cce2 | 348 | } |
3495cce2 | 349 | return iResult; |
350 | } | |
351 | ||
8ede8717 | 352 | int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const |
3495cce2 | 353 | { |
5f5b708b | 354 | // see header file for class documentation |
355 | ||
66043029 | 356 | int iResult=severity==kHLTLogNone || (severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0; |
3495cce2 | 357 | return iResult; |
358 | } | |
5f5b708b | 359 | |
360 | void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level) | |
361 | { | |
362 | // see header file for class documentation | |
363 | ||
66043029 | 364 | fgGlobalLogFilter=level; |
5f5b708b | 365 | } |
366 | ||
a742f6f8 | 367 | AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel() |
368 | { | |
369 | // see header file for class documentation | |
370 | ||
371 | return fgGlobalLogFilter; | |
372 | } | |
373 | ||
5f5b708b | 374 | void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level) |
375 | { | |
376 | // see header file for class documentation | |
377 | ||
378 | fLocalLogFilter=level; | |
379 | } | |
a742f6f8 | 380 | |
381 | ||
382 | AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel() | |
383 | { | |
384 | // see header file for class documentation | |
385 | ||
386 | return fLocalLogFilter; | |
387 | } | |
1e27470a | 388 | |
d76bc02a | 389 | int AliHLTLogging::CheckGroup(const char* /*originClass*/) const |
1e27470a | 390 | { |
391 | // see header file for class documentation | |
392 | ||
393 | return 1; | |
394 | } | |
395 | ||
396 | int AliHLTLogging::SetBlackList(const char* classnames) | |
397 | { | |
398 | // see header file for class documentation | |
399 | ||
400 | if (classnames) | |
401 | fgBlackList=classnames; | |
402 | return 0; | |
403 | } | |
404 | ||
405 | int AliHLTLogging::SetWhiteList(const char* classnames) | |
406 | { | |
407 | // see header file for class documentation | |
408 | ||
409 | if (classnames) | |
410 | fgWhiteList=classnames; | |
411 | return 0; | |
412 | } |