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 AliHLTLogging::~AliHLTLogging()
80 // see header file for class documentation
83 // the array will be grown dynamically, this is just an initial size
84 TArrayC AliHLTLogging::fgAliHLTLoggingTarget(200);
85 // the maximum size of the array
86 const int AliHLTLogging::fgkALIHLTLOGGINGMAXBUFFERSIZE=10000;
88 int AliHLTLogging::Init(AliHLTfctLogging pFun)
90 // see header file for class documentation
91 if (fgLoggingFunc!=NULL && fgLoggingFunc!=pFun) {
92 (*fgLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
99 int AliHLTLogging::InitAliLogTrap(AliHLTComponentHandler* pHandler)
101 // see header file for class documentation
104 AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel();
105 pHandler->SetLocalLoggingLevel(kHLTLogError);
106 pHandler->LoadLibrary("libAliHLTUtil.so");
107 pHandler->SetLocalLoggingLevel(loglevel);
108 InitAliDynamicMessageCallback pFunc=(InitAliDynamicMessageCallback)pHandler->FindSymbol("libAliHLTUtil.so", "InitAliDynamicMessageCallback");
112 Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogTrap", "init logging",
113 "can not initialize AliLog callback");
123 int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity,
124 const char* origin, const char* keyword,
127 // see header file for class documentation
130 // this is currently just to get rid of the warning "unused parameter"
133 const char* strSeverity="";
135 case kHLTLogBenchmark:
136 strSeverity="benchmark";
145 strSeverity="warning";
156 TString out="HLT Log ";
158 if (origin && origin[0]!=0) {out+=": <"; out+=origin; out+="> ";}
159 out+=" "; out+=message;
160 if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) {
161 out+=" ("; out+=keyword; out +=")";
163 cout << out.Data() << endl;
168 int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity,
169 const char* originClass, const char* originFunc,
170 const char* file, int line, const char* message)
172 // see header file for class documentation
175 case kHLTLogBenchmark:
176 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
179 AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
182 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
185 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
188 AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
191 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
200 const char* AliHLTLogging::BuildLogString(const char *format, va_list ap)
202 // see header file for class documentation
210 // take the first argument from the list as format string if no
212 const char* fmt = format;
213 if (fmt==NULL) fmt=va_arg(ap, const char*);
215 fgAliHLTLoggingTarget[0]=0;
217 iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray(), fgAliHLTLoggingTarget.GetSize(), fmt, ap);
219 // for compatibility with older version of vsnprintf
220 iResult=fgAliHLTLoggingTarget.GetSize()*2;
221 else if (iResult<fgAliHLTLoggingTarget.GetSize())
224 // terminate if buffer is already at the limit
225 if (fgAliHLTLoggingTarget.GetSize()>=fgkALIHLTLOGGINGMAXBUFFERSIZE)
227 fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0;
231 // check limitation and grow the buffer
232 if (iResult>fgkALIHLTLOGGINGMAXBUFFERSIZE) iResult=fgkALIHLTLOGGINGMAXBUFFERSIZE;
233 fgAliHLTLoggingTarget.Set(iResult+1);
235 // copy the original list and skip the first argument if this was the format string
240 fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0;
243 if (format==NULL) va_arg(ap, const char*);
249 return fgAliHLTLoggingTarget.GetArray();
252 int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity,
253 const char* origin, const char* keyword,
254 const char* format, ... )
256 // see header file for class documentation
257 int iResult=CheckFilter(severity);
260 va_start(args, format);
262 iResult = (*fgLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
264 if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
265 iResult=(*fgAliLoggingFunc)(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args ));
267 iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
274 int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity,
275 const char* originClass, const char* originFunc,
276 const char* file, int line, ... ) const
278 // see header file for class documentation
280 if (file==NULL && line==0) {
281 // this is currently just to get rid of the warning "unused parameter"
283 int iResult=CheckFilter(severity);
285 const char* separator="";
296 va_start(args, line);
299 iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
301 if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
302 iResult=(*fgAliLoggingFunc)(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args ));
304 iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
311 int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const
313 // see header file for class documentation
315 int iResult=severity==kHLTLogNone || (severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
319 void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level)
321 // see header file for class documentation
323 fgGlobalLogFilter=level;
326 AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel()
328 // see header file for class documentation
330 return fgGlobalLogFilter;
333 void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
335 // see header file for class documentation
337 fLocalLogFilter=level;
341 AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel()
343 // see header file for class documentation
345 return fLocalLogFilter;