3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line 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 #ifndef NOALIROOT_LOGGING
32 #include "AliHLTStdIncludes.h"
33 #include "AliHLTLogging.h"
41 /** target stream for AliRoot logging methods */
42 ostringstream gLogstr;
44 #ifndef NOALIROOT_LOGGING
46 * Notification callback for AliRoot logging methods
48 void LogNotification(AliLog::EType_t level, const char* message)
51 hltlog.SwitchAliLog(0);
52 hltlog.Logging(kHLTLogInfo, "NotificationHandler", "AliLog", gLogstr.str().c_str());
60 * The global logging buffer.
61 * The buffer is created with an initial size and grown dynamically on
64 TArrayC gAliHLTLoggingTarget(200);
66 /** the maximum size of the buffer */
67 const int gALIHLTLOGGING_MAXBUFFERSIZE=10000;
69 /** ROOT macro for the implementation of ROOT specific class methods */
70 ClassImp(AliHLTLogging)
72 AliHLTLogging::AliHLTLogging()
74 //fLocalLogFilter(kHLTLogDefault),
75 fLocalLogFilter(kHLTLogAll),
76 fpDefaultKeyword(NULL),
77 fpCurrentKeyword(NULL)
79 // see header file for class documentation
81 // refer to README to build package
83 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
86 AliHLTLogging::AliHLTLogging(const AliHLTLogging&)
88 fLocalLogFilter(kHLTLogAll),
89 fpDefaultKeyword(NULL),
90 fpCurrentKeyword(NULL)
92 // see header file for class documentation
93 HLTFatal("copy constructor untested");
96 AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&)
98 // see header file for class documentation
99 HLTFatal("assignment operator untested");
103 AliHLTComponentLogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll;
104 AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL;
105 int AliHLTLogging::fgUseAliLog=1;
107 AliHLTLogging::~AliHLTLogging()
109 // see header file for class documentation
112 int AliHLTLogging::Init(AliHLTfctLogging pFun)
114 // see header file for class documentation
115 if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) {
116 (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
119 // older versions of AliLog does not support the notification callback and
120 // stringstreams, but they support the logging macros in general
121 #ifndef NOALIROOT_LOGGING
122 #ifndef NO_ALILOG_NOTIFICATION
123 AliLog* log=new AliLog;
124 log->SetLogNotification(LogNotification);
125 log->SetStreamOutput(&gLogstr);
126 #endif // NO_ALILOG_NOTIFICATION
127 #endif // NOALIROOT_LOGGING
132 int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity,
133 const char* origin, const char* keyword,
136 // see header file for class documentation
139 // this is currently just to get rid of the warning "unused parameter"
142 const char* strSeverity="";
144 case kHLTLogBenchmark:
145 strSeverity="benchmark";
154 strSeverity="warning";
165 TString out="HLT Log ";
167 if (origin) {out+=": "; out+=origin;}
168 out+=" "; out+=message;
169 if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) {
170 out+=" ("; out+=keyword; out +=")";
172 cout << out.Data() << endl;
176 #ifndef NOALIROOT_LOGGING
177 int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity,
178 const char* origin_class, const char* origin_func,
179 const char* file, int line, const char* message)
181 // see header file for class documentation
184 case kHLTLogBenchmark:
185 AliLog::Message(AliLog::kInfo, message, "HLT", origin_class, origin_func, file, line);
188 AliLog::Message(AliLog::kDebug, message, "HLT", origin_class, origin_func, file, line);
191 AliLog::Message(AliLog::kInfo, message, "HLT", origin_class, origin_func, file, line);
194 AliLog::Message(AliLog::kWarning, message, "HLT", origin_class, origin_func, file, line);
197 AliLog::Message(AliLog::kError, message, "HLT", origin_class, origin_func, file, line);
200 AliLog::Message(AliLog::kWarning, message, "HLT", origin_class, origin_func, file, line);
209 const char* AliHLTLogging::BuildLogString(const char *format, va_list ap)
211 // see header file for class documentation
217 // take the first argument from the list as format string if no
219 const char* fmt = format;
220 if (fmt==NULL) fmt=va_arg(ap, const char*);
222 gAliHLTLoggingTarget[0]=0;
224 iResult=vsnprintf(gAliHLTLoggingTarget.GetArray(), gAliHLTLoggingTarget.GetSize(), fmt, ap);
226 // for compatibility with older version of vsnprintf
227 iResult=gAliHLTLoggingTarget.GetSize()*2;
228 else if (iResult<gAliHLTLoggingTarget.GetSize())
231 // terminate if buffer is already at the limit
232 if (gAliHLTLoggingTarget.GetSize()>=gALIHLTLOGGING_MAXBUFFERSIZE) {
233 gAliHLTLoggingTarget[gAliHLTLoggingTarget.GetSize()-1]=0;
237 // check limitation and grow the buffer
238 if (iResult>gALIHLTLOGGING_MAXBUFFERSIZE) iResult=gALIHLTLOGGING_MAXBUFFERSIZE;
239 gAliHLTLoggingTarget.Set(iResult+1);
241 // copy the original list and skip the first argument if this was the format string
244 if (format==NULL) va_arg(ap, const char*);
248 return gAliHLTLoggingTarget.GetArray();
251 int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity,
252 const char* origin, const char* keyword,
253 const char* format, ... )
255 // see header file for class documentation
256 int iResult=CheckFilter(severity);
259 va_start(args, format);
261 iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
263 #ifndef NOALIROOT_LOGGING
265 iResult=AliMessage(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args ));
268 iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
275 int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity,
276 const char* origin_class, const char* origin_func,
277 const char* file, int line, ... ) const
279 // see header file for class documentation
281 if (file==NULL && line==0) {
282 // this is currently just to get rid of the warning "unused parameter"
284 int iResult=CheckFilter(severity);
286 const char* separator="";
289 origin+=origin_class;
297 va_start(args, line);
300 iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
302 #ifndef NOALIROOT_LOGGING
304 iResult=AliMessage(severity, origin_class, origin_func, file, line, AliHLTLogging::BuildLogString(NULL, args ));
307 iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
314 int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const
316 // see header file for class documentation
318 int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
322 void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level)
324 // see header file for class documentation
326 fGlobalLogFilter=level;
329 void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
331 // see header file for class documentation
333 fLocalLogFilter=level;