]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTLogging.h
introducing function IsSelected which allows child classes to selectively publish...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.h
CommitLineData
098cca52 1//-*- Mode: C++ -*-
2// $Id$
3495cce2 3
4#ifndef ALIHLTLOGGING_H
5#define ALIHLTLOGGING_H
1e27470a 6/* This file is property of and copyright by the ALICE HLT Project *
7 * ALICE Experiment at CERN, All rights reserved. *
3495cce2 8 * See cxx source for full Copyright notice */
9
b22e91eb 10/** @file AliHLTLogging.h
11 @author Matthias Richter, Timm Steinbeck
12 @date
13 @brief HLT module logging primitives.
14*/
3495cce2 15
16#include "AliHLTDataTypes.h"
5f1685a0 17#include "AliHLTStdIncludes.h"
a1b2201f 18#include "TString.h"
fc455fba 19#include "TObject.h"
66043029 20#include "TArrayC.h"
3495cce2 21
a742f6f8 22class AliHLTComponentHandler;
85465857 23//#define LOG_PREFIX "" // logging prefix, for later extensions
3495cce2 24
db95fec3 25#define ALILOG_WRAPPER_LIBRARY "libHLTrec.so"
85465857 26
27/* the logging macros can be used inside methods of classes which inherit from
28 * AliHLTLogging
29 */
fc455fba 30// function name
31#if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
32#define FUNCTIONNAME() __FUNCTION__
33#else
34#define FUNCTIONNAME() "???"
a4a8ef64 35#endif
36
098cca52 37#ifndef ALIHLTLOGGINGVARIADICFREE_H
86a8c744 38// HLTMessage is not filtered
39#define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ )
40
41// the following macros are filtered by the Global and Local Log Filter
7850e451 42#define HLTLog( level, ... ) if (CheckFilter(level)) LoggingVarargs(level, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
fc455fba 43#define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
1e27470a 44#ifdef __DEBUG
45#define HLTDebug( ... ) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
46#else
47#define HLTDebug( ... )
48#endif
49#define HLTInfo( ... ) if (CheckFilter(kHLTLogInfo)) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
50#define HLTWarning( ... ) if (CheckFilter(kHLTLogWarning)) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
51#define HLTError( ... ) if (CheckFilter(kHLTLogError)) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
52#define HLTFatal( ... ) if (CheckFilter(kHLTLogFatal)) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
b2065764 53#define HLTImportant( ... ) if (CheckFilter(kHLTLogImportant))LoggingVarargs(kHLTLogImportant,Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
85465857 54
098cca52 55// the same macros are defined variadic free, in that case the message must be complete
56// include AliHLTLoggingVariadicFree.h
57#else //ALIHLTLOGGINGVARIADICFREE_H
86a8c744 58#define HLTMessage( message ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , message )
7850e451 59#define HLTLog( level, message) if (CheckFilter(level)) LoggingVarargs(level, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
098cca52 60#define HLTBenchmark( message ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
61#ifdef __DEBUG
62#define HLTDebug( message ) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
63#else
64#define HLTDebug( message )
65#endif
66#define HLTInfo( message ) if (CheckFilter(kHLTLogInfo)) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
67#define HLTWarning( message ) if (CheckFilter(kHLTLogWarning)) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
68#define HLTError( message ) if (CheckFilter(kHLTLogError)) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
69#define HLTFatal( message ) if (CheckFilter(kHLTLogFatal)) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
70#define HLTImportant( message ) if (CheckFilter(kHLTLogImportant))LoggingVarargs(kHLTLogImportant,Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , message )
71#endif //ALIHLTLOGGINGVARIADICFREE_H
72
85465857 73// helper macro to set the keyword
3a7c0444 74#define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey(this, a)
85465857 75
76#define HLT_DEFAULT_LOG_KEYWORD "no key"
3495cce2 77
66108417 78/**
79 * @class AliHLTLogging
80 * Basic logging class. All classes inherit the besic HLT logging functionality.
81 * Logging levels are controlled by a global logging filter and a local logging
82 * filter.
83 *
84 * @section alihlt_logging_levels Logging Levels
85 * Logging levels are switched by a bit pattern, AliHLTComponentLogSeverity {
86 * - ::kHLTLogNone no logging (0)
87 * - ::kHLTLogBenchmark benchmark messages (0x1)
88 * - ::kHLTLogDebug debug messages (0x2)
89 * - ::kHLTLogInfo info messages (0x4)
90 * - ::kHLTLogWarning warning messages (0x8)
91 * - ::kHLTLogError error messages (0x10)
92 * - ::kHLTLogFatal fatal error messages (0x20)
93 * - ::kHLTLogImportant few important messages not to be filtered out (0x40)
94 * - ::kHLTLogAll special value to enable all messages (0x7f)
95 * - ::kHLTLogDefault the default logging level: Warning, Error, Fatal, Important (0x79)
96 *
97 * @section alihlt_logging_filter Logging Filters
98 * The class provides a global and a local logging filter, the AND beween both
99 * defines whether a message is printed or not.
100 *
101 * The global filter is by default set to ::kHLTLogAll. Please note that AliHLTSystem
102 * changes the global logging level to ::kHLTLogDefault. The global filter can be
103 * adjusted by means of SetGlobalLoggingLevel().
104 *
105 * The local filter is set to ::kHLTLogAll and can be adjusted by
106 * SetLocalLoggingLevel(). The default can be changed for all objects by
107 * SetLocalLoggingDefault(). Please note that a change of the default level only
108 * applies to objects generated after the change of the default.
109 *
110 * @section alihlt_logging_external Redirection
111 * - external logging function
112 * - keyword
113 *
114 * @section alihlt_logging_aliroot AliRoot Redirection
115 * - switching of redirection
116 * - logging options in AliSimulation/AliReconstruction
117 *
118 * @ingroup alihlt_component
119 */
3495cce2 120class AliHLTLogging {
121public:
122 AliHLTLogging();
85869391 123 AliHLTLogging(const AliHLTLogging&);
124 AliHLTLogging& operator=(const AliHLTLogging&);
3495cce2 125 virtual ~AliHLTLogging();
126
a742f6f8 127 /** set the default key word
128 * the keyword is intended to simplify the use of logging macros
129 */
85465857 130 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
131
a742f6f8 132 /**
133 * Set a temporary keyword
d174bfc3 134 * Keywords need to be static const strings, the class handles only
135 * pointers and assumes the strings to be persistent.
a742f6f8 136 * returns the old key value
137 */
85465857 138 const char* SetKeyword(const char* keyword)
139 {
140 const char* currentKeyword=fpCurrentKeyword;
141 fpCurrentKeyword=keyword;
142 return currentKeyword;
143 }
144
a742f6f8 145 /**
146 * Get the current keyword
147 */
85869391 148 const char* GetKeyword() const
85465857 149 {
150 if (fpCurrentKeyword) return fpCurrentKeyword;
151 else if (fpDefaultKeyword) return fpDefaultKeyword;
152 return HLT_DEFAULT_LOG_KEYWORD;
153 }
3495cce2 154
a742f6f8 155 /**
156 * Init the AliLogging class for use from external package.
157 * This initializes the logging callback. <br>
158 * Only deployed by external users of the C wrapper interface, not used
159 * when running in AliRoot
160 */
bb16cc41 161 static int Init(AliHLTfctLogging pFun);
3495cce2 162
a742f6f8 163 /**
164 * Init the message trap in AliLog.
165 * This initializes the AliLog trap, the AliLog class is the logging
166 * mechanism of AliRoot. The trap can fetch log messages written to
167 * AliLog, components and detector algorithms can use the AliLog
168 * mechanism to be as close as possible to Offline habits. <br>
169 * Only used with external users of the C wrapper interface, not used
170 * when running in AliRoot
171 */
172 static int InitAliLogTrap(AliHLTComponentHandler* pHandler);
173
db95fec3 174 /**
175 * Init the AliRoot logging function.
176 * All log messages are redirected to AliLog when running in AliRoot.
177 * Note: when running in PubSub, AliLog messages are redirected to PubSub,
178 * see AliHLTLogging::InitAliLogTrap
179 */
180 static int InitAliLogFunc(AliHLTComponentHandler* pHandler);
181
a742f6f8 182 /**
183 * Genaral logging function
184 */
8ede8717 185 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
3495cce2 186
97d2b87a 187 /**
a742f6f8 188 * Logging function with two origin parameters, used by the log macros
189 */
97d2b87a 190 virtual int LoggingVarargs(AliHLTComponentLogSeverity severity,
191 const char* originClass, const char* originFunc,
192 const char* file, int line, ... ) const;
193
194 /**
195 * Send formatted string to the different channels
196 */
197 int SendMessage(AliHLTComponentLogSeverity severity,
198 const char* originClass, const char* originFunc,
199 const char* file, int line,
200 const char* message) const;
3495cce2 201
1e27470a 202 /**
203 * Evaluate the group of the debug message from the class name.
204 * @return 1 if message should be printed
205 */
206 int CheckGroup(const char* originClass) const;
207
208 /**
209 * Set the black list of classes.
210 * If the white list is set, debug messages are skipped for
211 * all classes matching one of the regular expressions in the string.
212 */
213 static int SetBlackList(const char* classnames);
214
215 /**
216 * Set the white list of classes.
217 * If the white list is set, debug messages are only printed for
218 * classes matching one of the regular expressions in the string.
219 */
220 static int SetWhiteList(const char* classnames);
221
a742f6f8 222 /**
223 * Apply filter
224 * @return 1 if message should pass
225 */
8ede8717 226 int CheckFilter(AliHLTComponentLogSeverity severity) const;
3495cce2 227
a742f6f8 228 /**
229 * Set global logging level
230 * logging filter for all objects
231 */
5f5b708b 232 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
233
a742f6f8 234 /**
235 * Get global logging level
236 * logging filter for all objects
237 */
238 static AliHLTComponentLogSeverity GetGlobalLoggingLevel();
239
240 /**
241 * Set local logging level
242 * logging filter for individual object
243 */
dba03d72 244 virtual void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
5f5b708b 245
66108417 246 /**
247 * Set local logging default
248 * Default logging filter for individual objects.
249 */
250 static void SetLocalLoggingDefault(AliHLTComponentLogSeverity level);
251
b618d95f 252 /**
253 * Get default setting for local logging filter for individual objects.
254 */
255 static AliHLTComponentLogSeverity GetLocalLoggingDefault() { return fgLocalLogDefault; }
256
fc455fba 257 /**
a742f6f8 258 * Get local logging level
259 * logging filter for individual object
fc455fba 260 */
a742f6f8 261 AliHLTComponentLogSeverity GetLocalLoggingLevel();
3495cce2 262
fc455fba 263 /**
a742f6f8 264 * Print message to stdout
fc455fba 265 */
a742f6f8 266 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
fc455fba 267
268 /**
269 * Build the log string from format specifier and variadac arguments
270 * @param format format string of printf style
271 * @param ap opened and initialized argument list
97d2b87a 272 * @param bAppend append to current content
273 * @return const char string with the formatted message
274 */
d4c23f36 275 static const char* BuildLogString(const char *format, va_list &ap, bool bAppend=false);
97d2b87a 276
277 /**
278 * Set the log string from format specifier and from variable arguments.
279 * @param format format string of printf style
fc455fba 280 * @return const char string with the formatted message
281 */
7efb6418 282 static const char* SetLogString(const void* p, const char* pfmt, const char *format, ... );
3495cce2 283
66043029 284 /**
285 * Get parameter given by the external caller.
286 * This functionality is not yet implemented. It is intended
287 * to pass the parameter pointer given to the component at
288 * initialization back to the caller.
289 */
290 virtual void* GetParameter() const {return NULL;}
fc455fba 291
292 /**
293 * Switch logging through AliLog on or off
294 * @param sw 1 = logging through AliLog
295 */
296 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
297
66043029 298 /** target stream for AliRoot logging methods */
299 static ostringstream fgLogstr; //! transient
a742f6f8 300
301 /**
302 * The message function for dynamic use.
303 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
304 * the library dynamically and looks for the symbol.
305 */
306 typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity,
307 const char* originClass,
308 const char* originFunc,
309 const char* file, int line,
310 const char* message);
311
312 /**
313 * The init function of the message callback for dynamic use.
314 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
315 * the library dynamically and looks for the symbol.
316 */
317 typedef int (*InitAliDynamicMessageCallback)();
66043029 318
3495cce2 319protected:
a742f6f8 320 /** the AliRoot logging function */
321 static AliHLTDynamicMessage fgAliLoggingFunc; //! transient
3495cce2 322
323private:
fc455fba 324 /** the global logging filter */
66043029 325 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
fc455fba 326 /** the local logging filter for one class */
327 AliHLTComponentLogSeverity fLocalLogFilter; // see above
66108417 328 /** the global logging filter */
329 static AliHLTComponentLogSeverity fgLocalLogDefault; // see above
fc455fba 330 /** logging callback from the framework */
66043029 331 static AliHLTfctLogging fgLoggingFunc; // see above
fc455fba 332 /** default keyword */
333 const char* fpDefaultKeyword; //! transient
334 /** current keyword */
335 const char* fpCurrentKeyword; //! transient
336 /** switch for logging through AliLog, default on */
337 static int fgUseAliLog; // see above
66043029 338 /**
339 * The global logging buffer.
340 * The buffer is created with an initial size and grown dynamically on
341 * demand.
342 */
343 static TArrayC fgAliHLTLoggingTarget; //! transient
344
345 /** the maximum size of the buffer */
346 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
1e27470a 347
348 /** groups of classes not to print debug messages */
349 static TString fgBlackList; //! transient
350
351 /** groups of classes not to print debug messages */
352 static TString fgWhiteList; //! transient
a742f6f8 353
9383b10c 354 ClassDef(AliHLTLogging, 0)
3495cce2 355};
85465857 356
357/* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
358 * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
359 * the object is destroyed automatically when the current scope is left and so the keyword is set
d174bfc3 360 * to the original value. Please note that all keywords need to be static strings, only pointyers
361 * are handled and the strings required to ber persistent.
85465857 362 */
363class AliHLTKeyword {
364 public:
365 AliHLTKeyword()
85869391 366 :
367 fpParent(NULL),
368 fpOriginal(NULL)
85465857 369 {
85465857 370 }
371
d174bfc3 372 AliHLTKeyword(const AliHLTLogging* parent, const char* keyword)
85869391 373 :
d174bfc3 374 fpParent(const_cast<AliHLTLogging*>(parent)),
85869391 375 fpOriginal(NULL)
85465857 376 {
d174bfc3 377 // the const cast is on purpose in order to be allowed to use
378 // HLTLogKeyword from const member functions
379 if (fpParent) {
85465857 380 fpOriginal=fpParent->SetKeyword(keyword);
381 }
382 }
383
384 ~AliHLTKeyword()
385 {
386 if (fpParent) {
387 fpParent->SetKeyword(fpOriginal);
388 }
389 }
390
391 private:
d174bfc3 392 /// copy constructor prohibited
393 AliHLTKeyword(const AliHLTKeyword& kw);
394 /// assignment operator prohibited
395 AliHLTKeyword& operator=(const AliHLTKeyword& kw);
396
66043029 397 AliHLTLogging* fpParent; //! transient
398 const char* fpOriginal; //! transient
85465857 399};
3495cce2 400#endif
401