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__ )
51 // helper macro to set the keyword
52 #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey(this, a)
54 #define HLT_DEFAULT_LOG_KEYWORD "no key"
59 AliHLTLogging(const AliHLTLogging&);
60 AliHLTLogging& operator=(const AliHLTLogging&);
61 virtual ~AliHLTLogging();
63 /** set the default key word
64 * the keyword is intended to simplify the use of logging macros
66 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
69 * Set a temporary keyword
70 * returns the old key value
72 const char* SetKeyword(const char* keyword)
74 const char* currentKeyword=fpCurrentKeyword;
75 fpCurrentKeyword=keyword;
76 return currentKeyword;
80 * Get the current keyword
82 const char* GetKeyword() const
84 if (fpCurrentKeyword) return fpCurrentKeyword;
85 else if (fpDefaultKeyword) return fpDefaultKeyword;
86 return HLT_DEFAULT_LOG_KEYWORD;
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
95 static int Init(AliHLTfctLogging pFun);
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
106 static int InitAliLogTrap(AliHLTComponentHandler* pHandler);
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
114 static int InitAliLogFunc(AliHLTComponentHandler* pHandler);
117 * Genaral logging function
119 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
122 * Logging function with two origin parameters, used by the log macros
124 int LoggingVarargs(AliHLTComponentLogSeverity severity,
125 const char* originClass, const char* originFunc,
126 const char* file, int line, ... ) const;
129 * Evaluate the group of the debug message from the class name.
130 * @return 1 if message should be printed
132 int CheckGroup(const char* originClass) const;
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.
139 static int SetBlackList(const char* classnames);
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.
146 static int SetWhiteList(const char* classnames);
150 * @return 1 if message should pass
152 int CheckFilter(AliHLTComponentLogSeverity severity) const;
155 * Set global logging level
156 * logging filter for all objects
158 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
161 * Get global logging level
162 * logging filter for all objects
164 static AliHLTComponentLogSeverity GetGlobalLoggingLevel();
167 * Set local logging level
168 * logging filter for individual object
170 virtual void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
173 * Get local logging level
174 * logging filter for individual object
176 AliHLTComponentLogSeverity GetLocalLoggingLevel();
179 * Print message to stdout
181 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
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
189 static const char* BuildLogString(const char *format, va_list ap);
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.
197 virtual void* GetParameter() const {return NULL;}
200 * Switch logging through AliLog on or off
201 * @param sw 1 = logging through AliLog
203 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
205 /** target stream for AliRoot logging methods */
206 static ostringstream fgLogstr; //! transient
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.
213 typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity,
214 const char* originClass,
215 const char* originFunc,
216 const char* file, int line,
217 const char* message);
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.
224 typedef int (*InitAliDynamicMessageCallback)();
227 /** the AliRoot logging function */
228 static AliHLTDynamicMessage fgAliLoggingFunc; //! transient
231 /** the global logging filter */
232 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
233 /** the local logging filter for one class */
234 AliHLTComponentLogSeverity fLocalLogFilter; // see above
235 /** logging callback from the framework */
236 static AliHLTfctLogging fgLoggingFunc; // see above
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
244 * The global logging buffer.
245 * The buffer is created with an initial size and grown dynamically on
248 static TArrayC fgAliHLTLoggingTarget; //! transient
250 /** the maximum size of the buffer */
251 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
253 /** groups of classes not to print debug messages */
254 static TString fgBlackList; //! transient
256 /** groups of classes not to print debug messages */
257 static TString fgWhiteList; //! transient
259 ClassDef(AliHLTLogging, 3)
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
267 class AliHLTKeyword {
276 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
282 fpOriginal=fpParent->SetKeyword(keyword);
286 AliHLTKeyword(const AliHLTKeyword& kw)
288 fpParent(kw.fpParent),
289 fpOriginal(kw.fpOriginal)
293 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
295 fpParent=kw.fpParent;
296 fpOriginal=kw.fpOriginal;
303 fpParent->SetKeyword(fpOriginal);
308 AliHLTLogging* fpParent; //! transient
309 const char* fpOriginal; //! transient