3 ///**************************************************************************
4 ///* This file is property of and copyright by the *
5 ///* ALICE Experiment at CERN, All rights reserved. *
7 ///* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 ///* for The ALICE HLT Project. *
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 ///**************************************************************************
19 /// @file AliHLTLogging.cxx
20 /// @author Matthias Richter, Timm Steinbeck
22 /// @brief Implementation of HLT logging primitives.
25 #include "AliHLTStdIncludes.h"
26 #include "AliHLTLogging.h"
27 #include "AliHLTComponentHandler.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTLogging);
41 AliHLTLogging::AliHLTLogging()
43 fLocalLogFilter(fgLocalLogDefault),
44 fpDefaultKeyword(NULL),
45 fpCurrentKeyword(NULL)
47 // see header file for class documentation
49 // refer to README to build package
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 AliHLTLogging::AliHLTLogging(const AliHLTLogging&)
56 fLocalLogFilter(kHLTLogAll),
57 fpDefaultKeyword(NULL),
58 fpCurrentKeyword(NULL)
60 // see header file for class documentation
61 HLTFatal("copy constructor untested");
64 AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&)
66 // see header file for class documentation
67 HLTFatal("assignment operator untested");
71 ostringstream AliHLTLogging::fgLogstr;
72 AliHLTComponentLogSeverity AliHLTLogging::fgGlobalLogFilter=kHLTLogAll;
73 AliHLTComponentLogSeverity AliHLTLogging::fgLocalLogDefault=kHLTLogAll;
74 AliHLTfctLogging AliHLTLogging::fgLoggingFunc=NULL;
75 AliHLTLogging::AliHLTDynamicMessage AliHLTLogging::fgAliLoggingFunc=NULL;
76 int AliHLTLogging::fgUseAliLog=1;
78 TString AliHLTLogging::fgBlackList="";
79 TString AliHLTLogging::fgWhiteList="";
81 AliHLTLogging::~AliHLTLogging()
83 // see header file for class documentation
86 // the array will be grown dynamically, this is just an initial size
87 TArrayC AliHLTLogging::fgAliHLTLoggingTarget(200);
88 // the maximum size of the array
89 const int AliHLTLogging::fgkALIHLTLOGGINGMAXBUFFERSIZE=10000;
91 int AliHLTLogging::Init(AliHLTfctLogging pFun)
93 // see header file for class documentation
94 if (fgLoggingFunc!=NULL && fgLoggingFunc!=pFun) {
95 (*fgLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
102 int AliHLTLogging::InitAliLogTrap(AliHLTComponentHandler* pHandler)
104 // see header file for class documentation
105 // init the AliRoot logging trap
106 // AliLog messages are redirected to PubSub,
109 // set temporary loglevel of component handler
110 AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel();
111 pHandler->SetLocalLoggingLevel(kHLTLogError);
113 // load library containing AliRoot dependencies and initialization handler
114 pHandler->LoadLibrary(ALILOG_WRAPPER_LIBRARY, 0/* do not activate agents */);
117 pHandler->SetLocalLoggingLevel(loglevel);
120 InitAliDynamicMessageCallback pFunc=(InitAliDynamicMessageCallback)pHandler->FindSymbol(ALILOG_WRAPPER_LIBRARY, "InitAliDynamicMessageCallback");
124 Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogTrap", "init logging",
125 "can not initialize AliLog callback");
135 int AliHLTLogging::InitAliLogFunc(AliHLTComponentHandler* pHandler)
137 // see header file for class documentation
140 // set temporary loglevel of component handler
141 AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel();
142 pHandler->SetLocalLoggingLevel(kHLTLogError);
144 // load library containing AliRoot dependencies and initialization handler
145 pHandler->LoadLibrary(ALILOG_WRAPPER_LIBRARY, 0/* do not activate agents */);
148 pHandler->SetLocalLoggingLevel(loglevel);
151 fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)pHandler->FindSymbol(ALILOG_WRAPPER_LIBRARY, "AliDynamicMessage");
152 if (fgAliLoggingFunc==NULL) {
153 Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogFunc", "init logging",
154 "symbol lookup failure: can not find AliDynamicMessage, switching to HLT logging system");
164 int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity,
165 const char* origin, const char* keyword,
168 // see header file for class documentation
171 // this is currently just to get rid of the warning "unused parameter"
174 const char* strSeverity="";
176 case kHLTLogBenchmark:
177 strSeverity="benchmark";
186 strSeverity="warning";
194 case kHLTLogImportant:
195 strSeverity="notify";
200 TString out="HLT Log ";
202 if (origin && origin[0]!=0) {out+=": <"; out+=origin; out+="> ";}
203 out+=" "; out+=message;
204 if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) {
205 out+=" ("; out+=keyword; out +=")";
207 cout << out.Data() << endl;
212 int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity,
213 const char* originClass, const char* originFunc,
214 const char* file, int line, const char* message)
216 // see header file for class documentation
219 case kHLTLogBenchmark:
220 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
223 AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
226 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
229 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
232 AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
235 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
244 const char* AliHLTLogging::BuildLogString(const char *format, va_list &ap, bool bAppend)
246 // see header file for class documentation
254 // take the first argument from the list as format string if no
256 const char* fmt = format;
257 if (fmt==NULL) fmt=va_arg(ap, const char*);
259 unsigned int iOffset=0;
261 iOffset=strlen(fgAliHLTLoggingTarget.GetArray());
263 fgAliHLTLoggingTarget[0]=0;
266 iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray()+iOffset, fgAliHLTLoggingTarget.GetSize()-iOffset, fmt, ap);
268 // for compatibility with older version of vsnprintf
269 iResult=fgAliHLTLoggingTarget.GetSize()*2;
273 if (iResult<fgAliHLTLoggingTarget.GetSize())
274 // everything in the limit
277 // terminate if buffer is already at the limit
278 if (fgAliHLTLoggingTarget.GetSize()>=fgkALIHLTLOGGINGMAXBUFFERSIZE)
280 fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0;
284 // check limitation and grow the buffer
285 if (iResult>fgkALIHLTLOGGINGMAXBUFFERSIZE) iResult=fgkALIHLTLOGGINGMAXBUFFERSIZE;
286 fgAliHLTLoggingTarget.Set(iResult+1);
288 // copy the original list and skip the first argument if this was the format string
293 fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0;
296 if (format==NULL) va_arg(ap, const char*);
302 return fgAliHLTLoggingTarget.GetArray();
305 const char* AliHLTLogging::SetLogString(const void* p, const char* pfmt, const char *format, ...)
307 // see header file for class documentation
308 if (!p || !pfmt) return NULL;
309 TString formatstr=format;
314 formatstr.ReplaceAll("_pfmt_", pstr);
316 va_start(args, format);
318 const char* message=BuildLogString(formatstr.Data(), args);
324 int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity,
325 const char* origin, const char* keyword,
326 const char* format, ... )
328 // see header file for class documentation
329 int iResult=CheckFilter(severity);
332 va_start(args, format);
334 iResult = (*fgLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
336 if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
337 iResult=(*fgAliLoggingFunc)(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args ));
339 iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
346 int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity,
347 const char* originClass, const char* originFunc,
348 const char* file, int line, ... ) const
350 // see header file for class documentation
354 va_start(args, line);
356 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args ));
362 int AliHLTLogging::SendMessage(AliHLTComponentLogSeverity severity,
363 const char* originClass, const char* originFunc,
364 const char* file, int line,
365 const char* message) const
367 // see header file for class documentation
369 const char* separator="";
381 iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), message);
383 if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
384 iResult=(*fgAliLoggingFunc)(severity, originClass, originFunc, file, line, message);
386 iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), message);
391 int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const
393 // see header file for class documentation
395 int iResult=severity==kHLTLogNone || ((severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0);
399 void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level)
401 // see header file for class documentation
403 fgGlobalLogFilter=level;
406 AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel()
408 // see header file for class documentation
410 return fgGlobalLogFilter;
413 void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
415 // see header file for class documentation
417 fLocalLogFilter=level;
421 AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel()
423 // see header file for class documentation
425 return fLocalLogFilter;
428 void AliHLTLogging::SetLocalLoggingDefault(AliHLTComponentLogSeverity level)
430 // see header file for class documentation
431 fgLocalLogDefault=level;
434 int AliHLTLogging::CheckGroup(const char* /*originClass*/) const
436 // see header file for class documentation
441 int AliHLTLogging::SetBlackList(const char* classnames)
443 // see header file for class documentation
446 fgBlackList=classnames;
450 int AliHLTLogging::SetWhiteList(const char* classnames)
452 // see header file for class documentation
455 fgWhiteList=classnames;