3 #ifndef ALIHLTLOGGING_H
4 #define ALIHLTLOGGING_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * See cxx source for full Copyright notice */
8 /** @file AliHLTLogging.h
9 @author Matthias Richter, Timm Steinbeck
11 @brief HLT module logging primitives.
14 #include "AliHLTDataTypes.h"
15 #include "AliHLTStdIncludes.h"
19 class AliHLTComponentHandler;
20 //#define LOG_PREFIX "" // logging prefix, for later extensions
23 /* the logging macros can be used inside methods of classes which inherit from
26 // HLTMessage is not filtered
27 #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ )
30 #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
31 #define FUNCTIONNAME() __FUNCTION__
33 #define FUNCTIONNAME() "???"
36 // the following macros are filtered by the Global and Local Log Filter
37 #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
38 #define HLTDebug( ... ) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
39 #define HLTInfo( ... ) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
40 #define HLTWarning( ... ) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
41 #define HLTError( ... ) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
42 #define HLTFatal( ... ) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
44 // helper macro to set the keyword
45 #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey__LINE__(this, a)
47 #define HLT_DEFAULT_LOG_KEYWORD "no key"
52 AliHLTLogging(const AliHLTLogging&);
53 AliHLTLogging& operator=(const AliHLTLogging&);
54 virtual ~AliHLTLogging();
56 /** set the default key word
57 * the keyword is intended to simplify the use of logging macros
59 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
62 * Set a temporary keyword
63 * returns the old key value
65 const char* SetKeyword(const char* keyword)
67 const char* currentKeyword=fpCurrentKeyword;
68 fpCurrentKeyword=keyword;
69 return currentKeyword;
73 * Get the current keyword
75 const char* GetKeyword() const
77 if (fpCurrentKeyword) return fpCurrentKeyword;
78 else if (fpDefaultKeyword) return fpDefaultKeyword;
79 return HLT_DEFAULT_LOG_KEYWORD;
83 * Init the AliLogging class for use from external package.
84 * This initializes the logging callback. <br>
85 * Only deployed by external users of the C wrapper interface, not used
86 * when running in AliRoot
88 static int Init(AliHLTfctLogging pFun);
91 * Init the message trap in AliLog.
92 * This initializes the AliLog trap, the AliLog class is the logging
93 * mechanism of AliRoot. The trap can fetch log messages written to
94 * AliLog, components and detector algorithms can use the AliLog
95 * mechanism to be as close as possible to Offline habits. <br>
96 * Only used with external users of the C wrapper interface, not used
97 * when running in AliRoot
99 static int InitAliLogTrap(AliHLTComponentHandler* pHandler);
102 * Genaral logging function
104 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
107 * Logging function with two origin parameters, used by the log macros
109 int LoggingVarargs(AliHLTComponentLogSeverity severity,
110 const char* originClass, const char* originFunc,
111 const char* file, int line, ... ) const;
115 * @return 1 if message should pass
117 int CheckFilter(AliHLTComponentLogSeverity severity) const;
120 * Set global logging level
121 * logging filter for all objects
123 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
126 * Get global logging level
127 * logging filter for all objects
129 static AliHLTComponentLogSeverity GetGlobalLoggingLevel();
132 * Set local logging level
133 * logging filter for individual object
135 void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
138 * Get local logging level
139 * logging filter for individual object
141 AliHLTComponentLogSeverity GetLocalLoggingLevel();
144 * Print message to stdout
146 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
149 * Build the log string from format specifier and variadac arguments
150 * @param format format string of printf style
151 * @param ap opened and initialized argument list
152 * @return const char string with the formatted message
154 static const char* BuildLogString(const char *format, va_list ap);
157 * Get parameter given by the external caller.
158 * This functionality is not yet implemented. It is intended
159 * to pass the parameter pointer given to the component at
160 * initialization back to the caller.
162 virtual void* GetParameter() const {return NULL;}
165 * Switch logging through AliLog on or off
166 * @param sw 1 = logging through AliLog
168 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
170 /** target stream for AliRoot logging methods */
171 static ostringstream fgLogstr; //! transient
174 * The message function for dynamic use.
175 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
176 * the library dynamically and looks for the symbol.
178 typedef int (*AliHLTDynamicMessage)(AliHLTComponentLogSeverity severity,
179 const char* originClass,
180 const char* originFunc,
181 const char* file, int line,
182 const char* message);
185 * The init function of the message callback for dynamic use.
186 * In order to avoid dependencies on AliRoot libraries, libHLTbase loads
187 * the library dynamically and looks for the symbol.
189 typedef int (*InitAliDynamicMessageCallback)();
192 /** the AliRoot logging function */
193 static AliHLTDynamicMessage fgAliLoggingFunc; //! transient
196 /** the global logging filter */
197 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
198 /** the local logging filter for one class */
199 AliHLTComponentLogSeverity fLocalLogFilter; // see above
200 /** logging callback from the framework */
201 static AliHLTfctLogging fgLoggingFunc; // see above
202 /** default keyword */
203 const char* fpDefaultKeyword; //! transient
204 /** current keyword */
205 const char* fpCurrentKeyword; //! transient
206 /** switch for logging through AliLog, default on */
207 static int fgUseAliLog; // see above
209 * The global logging buffer.
210 * The buffer is created with an initial size and grown dynamically on
213 static TArrayC fgAliHLTLoggingTarget; //! transient
215 /** the maximum size of the buffer */
216 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
218 ClassDef(AliHLTLogging, 2)
221 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
222 * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
223 * the object is destroyed automatically when the current scope is left and so the keyword is set
224 * to the original value
226 class AliHLTKeyword {
235 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
241 fpOriginal=fpParent->SetKeyword(keyword);
245 AliHLTKeyword(const AliHLTKeyword& kw)
247 fpParent(kw.fpParent),
248 fpOriginal(kw.fpOriginal)
252 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
254 fpParent=kw.fpParent;
255 fpOriginal=kw.fpOriginal;
262 fpParent->SetKeyword(fpOriginal);
267 AliHLTLogging* fpParent; //! transient
268 const char* fpOriginal; //! transient