3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
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.
29 #include "AliHLTStdIncludes.h"
30 #include "AliHLTLogging.h"
31 #include "AliHLTComponentHandler.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTLogging);
41 AliHLTLogging::AliHLTLogging()
43 //fLocalLogFilter(kHLTLogDefault),
44 fLocalLogFilter(kHLTLogAll),
45 fpDefaultKeyword(NULL),
46 fpCurrentKeyword(NULL)
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 AliHLTLogging::AliHLTLogging(const AliHLTLogging&)
57 fLocalLogFilter(kHLTLogAll),
58 fpDefaultKeyword(NULL),
59 fpCurrentKeyword(NULL)
61 // see header file for class documentation
62 HLTFatal("copy constructor untested");
65 AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&)
67 // see header file for class documentation
68 HLTFatal("assignment operator untested");
72 ostringstream AliHLTLogging::fgLogstr;
73 AliHLTComponentLogSeverity AliHLTLogging::fgGlobalLogFilter=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 lookp 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";
197 TString out="HLT Log ";
199 if (origin && origin[0]!=0) {out+=": <"; out+=origin; out+="> ";}
200 out+=" "; out+=message;
201 if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) {
202 out+=" ("; out+=keyword; out +=")";
204 cout << out.Data() << endl;
209 int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity,
210 const char* originClass, const char* originFunc,
211 const char* file, int line, const char* message)
213 // see header file for class documentation
216 case kHLTLogBenchmark:
217 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
220 AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
223 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
226 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
229 AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
232 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
241 const char* AliHLTLogging::BuildLogString(const char *format, va_list ap)
243 // see header file for class documentation
251 // take the first argument from the list as format string if no
253 const char* fmt = format;
254 if (fmt==NULL) fmt=va_arg(ap, const char*);
256 fgAliHLTLoggingTarget[0]=0;
258 iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray(), fgAliHLTLoggingTarget.GetSize(), fmt, ap);
260 // for compatibility with older version of vsnprintf
261 iResult=fgAliHLTLoggingTarget.GetSize()*2;
262 else if (iResult<fgAliHLTLoggingTarget.GetSize())
265 // terminate if buffer is already at the limit
266 if (fgAliHLTLoggingTarget.GetSize()>=fgkALIHLTLOGGINGMAXBUFFERSIZE)
268 fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0;
272 // check limitation and grow the buffer
273 if (iResult>fgkALIHLTLOGGINGMAXBUFFERSIZE) iResult=fgkALIHLTLOGGINGMAXBUFFERSIZE;
274 fgAliHLTLoggingTarget.Set(iResult+1);
276 // copy the original list and skip the first argument if this was the format string
281 fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0;
284 if (format==NULL) va_arg(ap, const char*);
290 return fgAliHLTLoggingTarget.GetArray();
293 int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity,
294 const char* origin, const char* keyword,
295 const char* format, ... )
297 // see header file for class documentation
298 int iResult=CheckFilter(severity);
301 va_start(args, format);
303 iResult = (*fgLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
305 if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
306 iResult=(*fgAliLoggingFunc)(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args ));
308 iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
315 int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity,
316 const char* originClass, const char* originFunc,
317 const char* file, int line, ... ) const
319 // see header file for class documentation
321 if (file==NULL && line==0) {
322 // this is currently just to get rid of the warning "unused parameter"
324 int iResult=1; //CheckFilter(severity); // check moved to makro
326 const char* separator="";
337 va_start(args, line);
340 iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
342 if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
343 iResult=(*fgAliLoggingFunc)(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args ));
345 iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
352 int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const
354 // see header file for class documentation
356 int iResult=severity==kHLTLogNone || (severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
360 void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level)
362 // see header file for class documentation
364 fgGlobalLogFilter=level;
367 AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel()
369 // see header file for class documentation
371 return fgGlobalLogFilter;
374 void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
376 // see header file for class documentation
378 fLocalLogFilter=level;
382 AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel()
384 // see header file for class documentation
386 return fLocalLogFilter;
389 int AliHLTLogging::CheckGroup(const char* /*originClass*/) const
391 // see header file for class documentation
396 int AliHLTLogging::SetBlackList(const char* classnames)
398 // see header file for class documentation
401 fgBlackList=classnames;
405 int AliHLTLogging::SetWhiteList(const char* classnames)
407 // see header file for class documentation
410 fgWhiteList=classnames;