3 #ifndef ALIHLTLOGGING_H
4 #define ALIHLTLOGGING_H
5 /* This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
7 * See cxx source for full Copyright notice */
9 /** @file AliHLTLogging.h
10 @author Matthias Richter, Timm Steinbeck
12 @brief HLT module logging primitives.
15 #include "AliHLTDataTypes.h"
16 #include "AliHLTStdIncludes.h"
21 class AliHLTComponentHandler;
22 //#define LOG_PREFIX "" // logging prefix, for later extensions
24 #define ALILOG_WRAPPER_LIBRARY "libHLTrec.so"
26 /* the logging macros can be used inside methods of classes which inherit from
29 // HLTMessage is not filtered
30 #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ )
33 #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
34 #define FUNCTIONNAME() __FUNCTION__
36 #define FUNCTIONNAME() "???"
39 // the following macros are filtered by the Global and Local Log Filter
40 #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
42 #define HLTDebug( ... ) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
44 #define HLTDebug( ... )
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__ )
50 #define HLTImportant( ... ) if (CheckFilter(kHLTLogImportant))LoggingVarargs(kHLTLogImportant,Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
52 // helper macro to set the keyword
53 #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey(this, a)
55 #define HLT_DEFAULT_LOG_KEYWORD "no key"
60 AliHLTLogging(const AliHLTLogging&);
61 AliHLTLogging& operator=(const AliHLTLogging&);
62 virtual ~AliHLTLogging();
64 /** set the default key word
65 * the keyword is intended to simplify the use of logging macros
67 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
70 * Set a temporary keyword
71 * returns the old key value
73 const char* SetKeyword(const char* keyword)
75 const char* currentKeyword=fpCurrentKeyword;
76 fpCurrentKeyword=keyword;
77 return currentKeyword;
81 * Get the current keyword
83 const char* GetKeyword() const
85 if (fpCurrentKeyword) return fpCurrentKeyword;
86 else if (fpDefaultKeyword) return fpDefaultKeyword;
87 return HLT_DEFAULT_LOG_KEYWORD;
91 * Init the AliLogging class for use from external package.
92 * This initializes the logging callback. <br>
93 * Only deployed by external users of the C wrapper interface, not used
94 * when running in AliRoot
96 static int Init(AliHLTfctLogging pFun);
99 * Init the message trap in AliLog.
100 * This initializes the AliLog trap, the AliLog class is the logging
101 * mechanism of AliRoot. The trap can fetch log messages written to
102 * AliLog, components and detector algorithms can use the AliLog
103 * mechanism to be as close as possible to Offline habits. <br>
104 * Only used with external users of the C wrapper interface, not used
105 * when running in AliRoot
107 static int InitAliLogTrap(AliHLTComponentHandler* pHandler);
110 * Init the AliRoot logging function.
111 * All log messages are redirected to AliLog when running in AliRoot.
112 * Note: when running in PubSub, AliLog messages are redirected to PubSub,
113 * see AliHLTLogging::InitAliLogTrap
115 static int InitAliLogFunc(AliHLTComponentHandler* pHandler);
118 * Genaral logging function
120 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
123 * Logging function with two origin parameters, used by the log macros
125 int LoggingVarargs(AliHLTComponentLogSeverity severity,
126 const char* originClass, const char* originFunc,
127 const char* file, int line, ... ) const;
130 * Evaluate the group of the debug message from the class name.
131 * @return 1 if message should be printed
133 int CheckGroup(const char* originClass) const;
136 * Set the black list of classes.
137 * If the white list is set, debug messages are skipped for
138 * all classes matching one of the regular expressions in the string.
140 static int SetBlackList(const char* classnames);
143 * Set the white list of classes.
144 * If the white list is set, debug messages are only printed for
145 * classes matching one of the regular expressions in the string.
147 static int SetWhiteList(const char* classnames);
151 * @return 1 if message should pass
153 int CheckFilter(AliHLTComponentLogSeverity severity) const;
156 * Set global logging level
157 * logging filter for all objects
159 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
162 * Get global logging level
163 * logging filter for all objects
165 static AliHLTComponentLogSeverity GetGlobalLoggingLevel();
168 * Set local logging level
169 * logging filter for individual object
171 virtual void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
174 * Get local logging level
175 * logging filter for individual object
177 AliHLTComponentLogSeverity GetLocalLoggingLevel();
180 * Print message to stdout
182 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
185 * Build the log string from format specifier and variadac arguments
186 * @param format format string of printf style
187 * @param ap opened and initialized argument list
188 * @return const char string with the formatted message
190 static const char* BuildLogString(const char *format, va_list ap);
193 * Get parameter given by the external caller.
194 * This functionality is not yet implemented. It is intended
195 * to pass the parameter pointer given to the component at
196 * initialization back to the caller.
198 virtual void* GetParameter() const {return NULL;}
201 * Switch logging through AliLog on or off
202 * @param sw 1 = logging through AliLog
204 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
206 /** target stream for AliRoot logging methods */
207 static ostringstream fgLogstr; //! transient
210 * The message function for dynamic use.
211 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
212 * the library dynamically and looks for the symbol.
214 typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity,
215 const char* originClass,
216 const char* originFunc,
217 const char* file, int line,
218 const char* message);
221 * The init function of the message callback for dynamic use.
222 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
223 * the library dynamically and looks for the symbol.
225 typedef int (*InitAliDynamicMessageCallback)();
228 /** the AliRoot logging function */
229 static AliHLTDynamicMessage fgAliLoggingFunc; //! transient
232 /** the global logging filter */
233 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
234 /** the local logging filter for one class */
235 AliHLTComponentLogSeverity fLocalLogFilter; // see above
236 /** logging callback from the framework */
237 static AliHLTfctLogging fgLoggingFunc; // see above
238 /** default keyword */
239 const char* fpDefaultKeyword; //! transient
240 /** current keyword */
241 const char* fpCurrentKeyword; //! transient
242 /** switch for logging through AliLog, default on */
243 static int fgUseAliLog; // see above
245 * The global logging buffer.
246 * The buffer is created with an initial size and grown dynamically on
249 static TArrayC fgAliHLTLoggingTarget; //! transient
251 /** the maximum size of the buffer */
252 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
254 /** groups of classes not to print debug messages */
255 static TString fgBlackList; //! transient
257 /** groups of classes not to print debug messages */
258 static TString fgWhiteList; //! transient
260 ClassDef(AliHLTLogging, 3)
263 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
264 * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
265 * the object is destroyed automatically when the current scope is left and so the keyword is set
266 * to the original value
268 class AliHLTKeyword {
277 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
283 fpOriginal=fpParent->SetKeyword(keyword);
287 AliHLTKeyword(const AliHLTKeyword& kw)
289 fpParent(kw.fpParent),
290 fpOriginal(kw.fpOriginal)
294 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
296 fpParent=kw.fpParent;
297 fpOriginal=kw.fpOriginal;
304 fpParent->SetKeyword(fpOriginal);
309 AliHLTLogging* fpParent; //! transient
310 const char* fpOriginal; //! transient