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"
20 class AliHLTComponentHandler;
21 //#define LOG_PREFIX "" // logging prefix, for later extensions
23 #define ALILOG_WRAPPER_LIBRARY "libHLTrec.so"
25 /* the logging macros can be used inside methods of classes which inherit from
28 // HLTMessage is not filtered
29 #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ )
32 #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
33 #define FUNCTIONNAME() __FUNCTION__
35 #define FUNCTIONNAME() "???"
38 // the following macros are filtered by the Global and Local Log Filter
39 #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
41 #define HLTDebug( ... ) if (CheckFilter(kHLTLogDebug) && CheckGroup(Class_Name())) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
43 #define HLTDebug( ... )
45 #define HLTInfo( ... ) if (CheckFilter(kHLTLogInfo)) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
46 #define HLTWarning( ... ) if (CheckFilter(kHLTLogWarning)) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
47 #define HLTError( ... ) if (CheckFilter(kHLTLogError)) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
48 #define HLTFatal( ... ) if (CheckFilter(kHLTLogFatal)) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
50 // helper macro to set the keyword
51 #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey(this, a)
53 #define HLT_DEFAULT_LOG_KEYWORD "no key"
58 AliHLTLogging(const AliHLTLogging&);
59 AliHLTLogging& operator=(const AliHLTLogging&);
60 virtual ~AliHLTLogging();
62 /** set the default key word
63 * the keyword is intended to simplify the use of logging macros
65 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
68 * Set a temporary keyword
69 * returns the old key value
71 const char* SetKeyword(const char* keyword)
73 const char* currentKeyword=fpCurrentKeyword;
74 fpCurrentKeyword=keyword;
75 return currentKeyword;
79 * Get the current keyword
81 const char* GetKeyword() const
83 if (fpCurrentKeyword) return fpCurrentKeyword;
84 else if (fpDefaultKeyword) return fpDefaultKeyword;
85 return HLT_DEFAULT_LOG_KEYWORD;
89 * Init the AliLogging class for use from external package.
90 * This initializes the logging callback. <br>
91 * Only deployed by external users of the C wrapper interface, not used
92 * when running in AliRoot
94 static int Init(AliHLTfctLogging pFun);
97 * Init the message trap in AliLog.
98 * This initializes the AliLog trap, the AliLog class is the logging
99 * mechanism of AliRoot. The trap can fetch log messages written to
100 * AliLog, components and detector algorithms can use the AliLog
101 * mechanism to be as close as possible to Offline habits. <br>
102 * Only used with external users of the C wrapper interface, not used
103 * when running in AliRoot
105 static int InitAliLogTrap(AliHLTComponentHandler* pHandler);
108 * Init the AliRoot logging function.
109 * All log messages are redirected to AliLog when running in AliRoot.
110 * Note: when running in PubSub, AliLog messages are redirected to PubSub,
111 * see AliHLTLogging::InitAliLogTrap
113 static int InitAliLogFunc(AliHLTComponentHandler* pHandler);
116 * Genaral logging function
118 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
121 * Logging function with two origin parameters, used by the log macros
123 int LoggingVarargs(AliHLTComponentLogSeverity severity,
124 const char* originClass, const char* originFunc,
125 const char* file, int line, ... ) const;
128 * Evaluate the group of the debug message from the class name.
129 * @return 1 if message should be printed
131 int CheckGroup(const char* originClass) const;
134 * Set the black list of classes.
135 * If the white list is set, debug messages are skipped for
136 * all classes matching one of the regular expressions in the string.
138 static int SetBlackList(const char* classnames);
141 * Set the white list of classes.
142 * If the white list is set, debug messages are only printed for
143 * classes matching one of the regular expressions in the string.
145 static int SetWhiteList(const char* classnames);
149 * @return 1 if message should pass
151 int CheckFilter(AliHLTComponentLogSeverity severity) const;
154 * Set global logging level
155 * logging filter for all objects
157 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
160 * Get global logging level
161 * logging filter for all objects
163 static AliHLTComponentLogSeverity GetGlobalLoggingLevel();
166 * Set local logging level
167 * logging filter for individual object
169 void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
172 * Get local logging level
173 * logging filter for individual object
175 AliHLTComponentLogSeverity GetLocalLoggingLevel();
178 * Print message to stdout
180 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
183 * Build the log string from format specifier and variadac arguments
184 * @param format format string of printf style
185 * @param ap opened and initialized argument list
186 * @return const char string with the formatted message
188 static const char* BuildLogString(const char *format, va_list ap);
191 * Get parameter given by the external caller.
192 * This functionality is not yet implemented. It is intended
193 * to pass the parameter pointer given to the component at
194 * initialization back to the caller.
196 virtual void* GetParameter() const {return NULL;}
199 * Switch logging through AliLog on or off
200 * @param sw 1 = logging through AliLog
202 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
204 /** target stream for AliRoot logging methods */
205 static ostringstream fgLogstr; //! transient
208 * The message function for dynamic use.
209 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
210 * the library dynamically and looks for the symbol.
212 typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity,
213 const char* originClass,
214 const char* originFunc,
215 const char* file, int line,
216 const char* message);
219 * The init function of the message callback for dynamic use.
220 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
221 * the library dynamically and looks for the symbol.
223 typedef int (*InitAliDynamicMessageCallback)();
226 /** the AliRoot logging function */
227 static AliHLTDynamicMessage fgAliLoggingFunc; //! transient
230 /** the global logging filter */
231 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
232 /** the local logging filter for one class */
233 AliHLTComponentLogSeverity fLocalLogFilter; // see above
234 /** logging callback from the framework */
235 static AliHLTfctLogging fgLoggingFunc; // see above
236 /** default keyword */
237 const char* fpDefaultKeyword; //! transient
238 /** current keyword */
239 const char* fpCurrentKeyword; //! transient
240 /** switch for logging through AliLog, default on */
241 static int fgUseAliLog; // see above
243 * The global logging buffer.
244 * The buffer is created with an initial size and grown dynamically on
247 static TArrayC fgAliHLTLoggingTarget; //! transient
249 /** the maximum size of the buffer */
250 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
252 /** groups of classes not to print debug messages */
253 static TString fgBlackList; //! transient
255 /** groups of classes not to print debug messages */
256 static TString fgWhiteList; //! transient
258 ClassDef(AliHLTLogging, 3)
261 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
262 * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
263 * the object is destroyed automatically when the current scope is left and so the keyword is set
264 * to the original value
266 class AliHLTKeyword {
275 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
281 fpOriginal=fpParent->SetKeyword(keyword);
285 AliHLTKeyword(const AliHLTKeyword& kw)
287 fpParent(kw.fpParent),
288 fpOriginal(kw.fpOriginal)
292 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
294 fpParent=kw.fpParent;
295 fpOriginal=kw.fpOriginal;
302 fpParent->SetKeyword(fpOriginal);
307 AliHLTLogging* fpParent; //! transient
308 const char* fpOriginal; //! transient