]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTLogging.h
- abandon TPCLib backward compatibility check for AliRoot releases < v4-03
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.h
CommitLineData
fc455fba 1// @(#) $Id$
3495cce2 2
3#ifndef ALIHLTLOGGING_H
4#define ALIHLTLOGGING_H
1e27470a 5/* This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
3495cce2 7 * See cxx source for full Copyright notice */
8
b22e91eb 9/** @file AliHLTLogging.h
10 @author Matthias Richter, Timm Steinbeck
11 @date
12 @brief HLT module logging primitives.
13*/
3495cce2 14
15#include "AliHLTDataTypes.h"
5f1685a0 16#include "AliHLTStdIncludes.h"
a1b2201f 17#include "TString.h"
fc455fba 18#include "TObject.h"
66043029 19#include "TArrayC.h"
3495cce2 20
a742f6f8 21class AliHLTComponentHandler;
85465857 22//#define LOG_PREFIX "" // logging prefix, for later extensions
3495cce2 23
db95fec3 24#define ALILOG_WRAPPER_LIBRARY "libHLTrec.so"
85465857 25
26/* the logging macros can be used inside methods of classes which inherit from
27 * AliHLTLogging
28 */
29// HLTMessage is not filtered
fc455fba 30#define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ )
85465857 31
fc455fba 32// function name
33#if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
34#define FUNCTIONNAME() __FUNCTION__
35#else
36#define FUNCTIONNAME() "???"
a4a8ef64 37#endif
38
85465857 39// the following macros are filtered by the Global and Local Log Filter
fc455fba 40#define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
1e27470a 41#ifdef __DEBUG
42#define HLTDebug( ... ) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
43#else
44#define HLTDebug( ... )
45#endif
46#define HLTInfo( ... ) if (CheckFilter(kHLTLogInfo)) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
47#define HLTWarning( ... ) if (CheckFilter(kHLTLogWarning)) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
48#define HLTError( ... ) if (CheckFilter(kHLTLogError)) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
49#define HLTFatal( ... ) if (CheckFilter(kHLTLogFatal)) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
85465857 50
51// helper macro to set the keyword
3a7c0444 52#define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey(this, a)
85465857 53
54#define HLT_DEFAULT_LOG_KEYWORD "no key"
3495cce2 55
56class AliHLTLogging {
57public:
58 AliHLTLogging();
85869391 59 AliHLTLogging(const AliHLTLogging&);
60 AliHLTLogging& operator=(const AliHLTLogging&);
3495cce2 61 virtual ~AliHLTLogging();
62
a742f6f8 63 /** set the default key word
64 * the keyword is intended to simplify the use of logging macros
65 */
85465857 66 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
67
a742f6f8 68 /**
69 * Set a temporary keyword
70 * returns the old key value
71 */
85465857 72 const char* SetKeyword(const char* keyword)
73 {
74 const char* currentKeyword=fpCurrentKeyword;
75 fpCurrentKeyword=keyword;
76 return currentKeyword;
77 }
78
a742f6f8 79 /**
80 * Get the current keyword
81 */
85869391 82 const char* GetKeyword() const
85465857 83 {
84 if (fpCurrentKeyword) return fpCurrentKeyword;
85 else if (fpDefaultKeyword) return fpDefaultKeyword;
86 return HLT_DEFAULT_LOG_KEYWORD;
87 }
3495cce2 88
a742f6f8 89 /**
90 * Init the AliLogging class for use from external package.
91 * This initializes the logging callback. <br>
92 * Only deployed by external users of the C wrapper interface, not used
93 * when running in AliRoot
94 */
bb16cc41 95 static int Init(AliHLTfctLogging pFun);
3495cce2 96
a742f6f8 97 /**
98 * Init the message trap in AliLog.
99 * This initializes the AliLog trap, the AliLog class is the logging
100 * mechanism of AliRoot. The trap can fetch log messages written to
101 * AliLog, components and detector algorithms can use the AliLog
102 * mechanism to be as close as possible to Offline habits. <br>
103 * Only used with external users of the C wrapper interface, not used
104 * when running in AliRoot
105 */
106 static int InitAliLogTrap(AliHLTComponentHandler* pHandler);
107
db95fec3 108 /**
109 * Init the AliRoot logging function.
110 * All log messages are redirected to AliLog when running in AliRoot.
111 * Note: when running in PubSub, AliLog messages are redirected to PubSub,
112 * see AliHLTLogging::InitAliLogTrap
113 */
114 static int InitAliLogFunc(AliHLTComponentHandler* pHandler);
115
a742f6f8 116 /**
117 * Genaral logging function
118 */
8ede8717 119 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
3495cce2 120
a742f6f8 121 /*
122 * Logging function with two origin parameters, used by the log macros
123 */
fc455fba 124 int LoggingVarargs(AliHLTComponentLogSeverity severity,
66043029 125 const char* originClass, const char* originFunc,
fc455fba 126 const char* file, int line, ... ) const;
3495cce2 127
1e27470a 128 /**
129 * Evaluate the group of the debug message from the class name.
130 * @return 1 if message should be printed
131 */
132 int CheckGroup(const char* originClass) const;
133
134 /**
135 * Set the black list of classes.
136 * If the white list is set, debug messages are skipped for
137 * all classes matching one of the regular expressions in the string.
138 */
139 static int SetBlackList(const char* classnames);
140
141 /**
142 * Set the white list of classes.
143 * If the white list is set, debug messages are only printed for
144 * classes matching one of the regular expressions in the string.
145 */
146 static int SetWhiteList(const char* classnames);
147
a742f6f8 148 /**
149 * Apply filter
150 * @return 1 if message should pass
151 */
8ede8717 152 int CheckFilter(AliHLTComponentLogSeverity severity) const;
3495cce2 153
a742f6f8 154 /**
155 * Set global logging level
156 * logging filter for all objects
157 */
5f5b708b 158 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
159
a742f6f8 160 /**
161 * Get global logging level
162 * logging filter for all objects
163 */
164 static AliHLTComponentLogSeverity GetGlobalLoggingLevel();
165
166 /**
167 * Set local logging level
168 * logging filter for individual object
169 */
dba03d72 170 virtual void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
5f5b708b 171
fc455fba 172 /**
a742f6f8 173 * Get local logging level
174 * logging filter for individual object
fc455fba 175 */
a742f6f8 176 AliHLTComponentLogSeverity GetLocalLoggingLevel();
3495cce2 177
fc455fba 178 /**
a742f6f8 179 * Print message to stdout
fc455fba 180 */
a742f6f8 181 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
fc455fba 182
183 /**
184 * Build the log string from format specifier and variadac arguments
185 * @param format format string of printf style
186 * @param ap opened and initialized argument list
187 * @return const char string with the formatted message
188 */
3495cce2 189 static const char* BuildLogString(const char *format, va_list ap);
190
66043029 191 /**
192 * Get parameter given by the external caller.
193 * This functionality is not yet implemented. It is intended
194 * to pass the parameter pointer given to the component at
195 * initialization back to the caller.
196 */
197 virtual void* GetParameter() const {return NULL;}
fc455fba 198
199 /**
200 * Switch logging through AliLog on or off
201 * @param sw 1 = logging through AliLog
202 */
203 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
204
66043029 205 /** target stream for AliRoot logging methods */
206 static ostringstream fgLogstr; //! transient
a742f6f8 207
208 /**
209 * The message function for dynamic use.
210 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
211 * the library dynamically and looks for the symbol.
212 */
213 typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity,
214 const char* originClass,
215 const char* originFunc,
216 const char* file, int line,
217 const char* message);
218
219 /**
220 * The init function of the message callback for dynamic use.
221 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
222 * the library dynamically and looks for the symbol.
223 */
224 typedef int (*InitAliDynamicMessageCallback)();
66043029 225
3495cce2 226protected:
a742f6f8 227 /** the AliRoot logging function */
228 static AliHLTDynamicMessage fgAliLoggingFunc; //! transient
3495cce2 229
230private:
fc455fba 231 /** the global logging filter */
66043029 232 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
fc455fba 233 /** the local logging filter for one class */
234 AliHLTComponentLogSeverity fLocalLogFilter; // see above
235 /** logging callback from the framework */
66043029 236 static AliHLTfctLogging fgLoggingFunc; // see above
fc455fba 237 /** default keyword */
238 const char* fpDefaultKeyword; //! transient
239 /** current keyword */
240 const char* fpCurrentKeyword; //! transient
241 /** switch for logging through AliLog, default on */
242 static int fgUseAliLog; // see above
66043029 243 /**
244 * The global logging buffer.
245 * The buffer is created with an initial size and grown dynamically on
246 * demand.
247 */
248 static TArrayC fgAliHLTLoggingTarget; //! transient
249
250 /** the maximum size of the buffer */
251 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
1e27470a 252
253 /** groups of classes not to print debug messages */
254 static TString fgBlackList; //! transient
255
256 /** groups of classes not to print debug messages */
257 static TString fgWhiteList; //! transient
a742f6f8 258
1e27470a 259 ClassDef(AliHLTLogging, 3)
3495cce2 260};
85465857 261
262/* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
263 * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
264 * the object is destroyed automatically when the current scope is left and so the keyword is set
265 * to the original value
266 */
267class AliHLTKeyword {
268 public:
269 AliHLTKeyword()
85869391 270 :
271 fpParent(NULL),
272 fpOriginal(NULL)
85465857 273 {
85465857 274 }
275
276 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
85869391 277 :
278 fpParent(parent),
279 fpOriginal(NULL)
85465857 280 {
85465857 281 if (parent) {
85465857 282 fpOriginal=fpParent->SetKeyword(keyword);
283 }
284 }
285
85869391 286 AliHLTKeyword(const AliHLTKeyword& kw)
287 :
288 fpParent(kw.fpParent),
289 fpOriginal(kw.fpOriginal)
290 {
291 }
292
293 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
294 {
295 fpParent=kw.fpParent;
296 fpOriginal=kw.fpOriginal;
297 return *this;
298 }
299
85465857 300 ~AliHLTKeyword()
301 {
302 if (fpParent) {
303 fpParent->SetKeyword(fpOriginal);
304 }
305 }
306
307 private:
66043029 308 AliHLTLogging* fpParent; //! transient
309 const char* fpOriginal; //! transient
85465857 310};
3495cce2 311#endif
312