]>
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 | |
105 | int iResult=0; | |
106 | if (pHandler) { | |
107 | AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel(); | |
108 | pHandler->SetLocalLoggingLevel(kHLTLogError); | |
109 | pHandler->LoadLibrary("libAliHLTUtil.so"); | |
110 | pHandler->SetLocalLoggingLevel(loglevel); | |
111 | InitAliDynamicMessageCallback pFunc=(InitAliDynamicMessageCallback)pHandler->FindSymbol("libAliHLTUtil.so", "InitAliDynamicMessageCallback"); | |
112 | if (pFunc) { | |
113 | iResult=(*pFunc)(); | |
114 | } else { | |
115 | Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogTrap", "init logging", | |
116 | "can not initialize AliLog callback"); | |
117 | iResult=-ENOSYS; | |
118 | } | |
119 | } else { | |
120 | iResult=-EINVAL; | |
121 | } | |
122 | ||
123 | return iResult; | |
124 | } | |
125 | ||
fc455fba | 126 | int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity, |
127 | const char* origin, const char* keyword, | |
128 | const char* message) | |
5f5b708b | 129 | { |
130 | // see header file for class documentation | |
3495cce2 | 131 | int iResult=0; |
53feaef5 | 132 | if (param==NULL) { |
133 | // this is currently just to get rid of the warning "unused parameter" | |
134 | } | |
fc455fba | 135 | |
3495cce2 | 136 | const char* strSeverity=""; |
137 | switch (severity) { | |
138 | case kHLTLogBenchmark: | |
139 | strSeverity="benchmark"; | |
140 | break; | |
141 | case kHLTLogDebug: | |
142 | strSeverity="debug"; | |
143 | break; | |
144 | case kHLTLogInfo: | |
145 | strSeverity="info"; | |
146 | break; | |
147 | case kHLTLogWarning: | |
148 | strSeverity="warning"; | |
149 | break; | |
150 | case kHLTLogError: | |
151 | strSeverity="error"; | |
152 | break; | |
153 | case kHLTLogFatal: | |
154 | strSeverity="fatal"; | |
155 | break; | |
156 | default: | |
157 | break; | |
158 | } | |
3cde846d | 159 | TString out="HLT Log "; |
160 | out+=strSeverity; | |
d54f579e | 161 | if (origin && origin[0]!=0) {out+=": <"; out+=origin; out+="> ";} |
3cde846d | 162 | out+=" "; out+=message; |
163 | if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) { | |
164 | out+=" ("; out+=keyword; out +=")"; | |
165 | } | |
166 | cout << out.Data() << endl; | |
3495cce2 | 167 | return iResult; |
168 | } | |
169 | ||
a742f6f8 | 170 | #if 0 |
fc455fba | 171 | int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity, |
66043029 | 172 | const char* originClass, const char* originFunc, |
fc455fba | 173 | const char* file, int line, const char* message) |
5f5b708b | 174 | { |
175 | // see header file for class documentation | |
3495cce2 | 176 | |
fc455fba | 177 | switch (severity) { |
178 | case kHLTLogBenchmark: | |
66043029 | 179 | AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 180 | break; |
181 | case kHLTLogDebug: | |
66043029 | 182 | AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 183 | break; |
184 | case kHLTLogInfo: | |
66043029 | 185 | AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 186 | break; |
187 | case kHLTLogWarning: | |
66043029 | 188 | AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 189 | break; |
190 | case kHLTLogError: | |
66043029 | 191 | AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 192 | break; |
193 | case kHLTLogFatal: | |
66043029 | 194 | AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line); |
fc455fba | 195 | break; |
196 | default: | |
197 | break; | |
198 | } | |
199 | return 0; | |
200 | } | |
85465857 | 201 | #endif |
fc455fba | 202 | |
203 | const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) | |
204 | { | |
205 | // see header file for class documentation | |
206 | ||
207 | int iResult=0; | |
a59b461e | 208 | #ifdef R__VA_COPY |
fc455fba | 209 | va_list bap; |
210 | R__VA_COPY(bap, ap); | |
a59b461e | 211 | #endif //R__VA_COPY |
fc455fba | 212 | |
213 | // take the first argument from the list as format string if no | |
214 | // format was given | |
215 | const char* fmt = format; | |
216 | if (fmt==NULL) fmt=va_arg(ap, const char*); | |
217 | ||
66043029 | 218 | fgAliHLTLoggingTarget[0]=0; |
fc455fba | 219 | while (fmt!=NULL) { |
66043029 | 220 | iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray(), fgAliHLTLoggingTarget.GetSize(), fmt, ap); |
fc455fba | 221 | if (iResult==-1) |
222 | // for compatibility with older version of vsnprintf | |
66043029 | 223 | iResult=fgAliHLTLoggingTarget.GetSize()*2; |
224 | else if (iResult<fgAliHLTLoggingTarget.GetSize()) | |
fc455fba | 225 | break; |
226 | ||
227 | // terminate if buffer is already at the limit | |
66043029 | 228 | if (fgAliHLTLoggingTarget.GetSize()>=fgkALIHLTLOGGINGMAXBUFFERSIZE) |
a59b461e | 229 | { |
66043029 | 230 | fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0; |
fc455fba | 231 | break; |
3495cce2 | 232 | } |
fc455fba | 233 | |
234 | // check limitation and grow the buffer | |
66043029 | 235 | if (iResult>fgkALIHLTLOGGINGMAXBUFFERSIZE) iResult=fgkALIHLTLOGGINGMAXBUFFERSIZE; |
236 | fgAliHLTLoggingTarget.Set(iResult+1); | |
fc455fba | 237 | |
238 | // copy the original list and skip the first argument if this was the format string | |
a59b461e | 239 | #ifdef R__VA_COPY |
fc455fba | 240 | va_end(ap); |
241 | R__VA_COPY(ap, bap); | |
a59b461e | 242 | #else |
66043029 | 243 | fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0; |
a59b461e | 244 | break; |
245 | #endif //R__VA_COPY | |
fc455fba | 246 | if (format==NULL) va_arg(ap, const char*); |
247 | } | |
a59b461e | 248 | #ifdef R__VA_COPY |
fc455fba | 249 | va_end(bap); |
a59b461e | 250 | #endif //R__VA_COPY |
fc455fba | 251 | |
66043029 | 252 | return fgAliHLTLoggingTarget.GetArray(); |
3495cce2 | 253 | } |
254 | ||
fc455fba | 255 | int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, |
256 | const char* origin, const char* keyword, | |
257 | const char* format, ... ) | |
5f5b708b | 258 | { |
259 | // see header file for class documentation | |
85465857 | 260 | int iResult=CheckFilter(severity); |
261 | if (iResult>0) { | |
262 | va_list args; | |
263 | va_start(args, format); | |
66043029 | 264 | if (fgLoggingFunc) { |
265 | iResult = (*fgLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); | |
85465857 | 266 | } else { |
a742f6f8 | 267 | if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL) |
268 | iResult=(*fgAliLoggingFunc)(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args )); | |
fc455fba | 269 | else |
fc455fba | 270 | iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); |
85465857 | 271 | } |
fc455fba | 272 | va_end(args); |
3495cce2 | 273 | } |
85465857 | 274 | return iResult; |
3495cce2 | 275 | } |
276 | ||
fc455fba | 277 | int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity, |
66043029 | 278 | const char* originClass, const char* originFunc, |
fc455fba | 279 | const char* file, int line, ... ) const |
3495cce2 | 280 | { |
5f5b708b | 281 | // see header file for class documentation |
282 | ||
fc455fba | 283 | if (file==NULL && line==0) { |
284 | // this is currently just to get rid of the warning "unused parameter" | |
285 | } | |
1e27470a | 286 | int iResult=1; //CheckFilter(severity); // check moved to makro |
85465857 | 287 | if (iResult>0) { |
85465857 | 288 | const char* separator=""; |
fc455fba | 289 | TString origin; |
66043029 | 290 | if (originClass) { |
291 | origin+=originClass; | |
85465857 | 292 | separator="::"; |
3495cce2 | 293 | } |
66043029 | 294 | if (originFunc) { |
fc455fba | 295 | origin+=separator; |
66043029 | 296 | origin+=originFunc; |
3495cce2 | 297 | } |
85465857 | 298 | va_list args; |
fc455fba | 299 | va_start(args, line); |
85465857 | 300 | |
66043029 | 301 | if (fgLoggingFunc) { |
302 | iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args )); | |
85465857 | 303 | } else { |
a742f6f8 | 304 | if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL) |
305 | iResult=(*fgAliLoggingFunc)(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args )); | |
fc455fba | 306 | else |
fc455fba | 307 | iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args )); |
85465857 | 308 | } |
309 | va_end(args); | |
3495cce2 | 310 | } |
3495cce2 | 311 | return iResult; |
312 | } | |
313 | ||
8ede8717 | 314 | int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const |
3495cce2 | 315 | { |
5f5b708b | 316 | // see header file for class documentation |
317 | ||
66043029 | 318 | int iResult=severity==kHLTLogNone || (severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0; |
3495cce2 | 319 | return iResult; |
320 | } | |
5f5b708b | 321 | |
322 | void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level) | |
323 | { | |
324 | // see header file for class documentation | |
325 | ||
66043029 | 326 | fgGlobalLogFilter=level; |
5f5b708b | 327 | } |
328 | ||
a742f6f8 | 329 | AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel() |
330 | { | |
331 | // see header file for class documentation | |
332 | ||
333 | return fgGlobalLogFilter; | |
334 | } | |
335 | ||
5f5b708b | 336 | void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level) |
337 | { | |
338 | // see header file for class documentation | |
339 | ||
340 | fLocalLogFilter=level; | |
341 | } | |
a742f6f8 | 342 | |
343 | ||
344 | AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel() | |
345 | { | |
346 | // see header file for class documentation | |
347 | ||
348 | return fLocalLogFilter; | |
349 | } | |
1e27470a | 350 | |
351 | int AliHLTLogging::CheckGroup(const char* originClass) const | |
352 | { | |
353 | // see header file for class documentation | |
354 | ||
355 | return 1; | |
356 | } | |
357 | ||
358 | int AliHLTLogging::SetBlackList(const char* classnames) | |
359 | { | |
360 | // see header file for class documentation | |
361 | ||
362 | if (classnames) | |
363 | fgBlackList=classnames; | |
364 | return 0; | |
365 | } | |
366 | ||
367 | int AliHLTLogging::SetWhiteList(const char* classnames) | |
368 | { | |
369 | // see header file for class documentation | |
370 | ||
371 | if (classnames) | |
372 | fgWhiteList=classnames; | |
373 | return 0; | |
374 | } |