]>
Commit | Line | Data |
---|---|---|
fc455fba | 1 | // @(#) $Id$ |
3495cce2 | 2 | |
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 */ | |
7 | ||
b22e91eb | 8 | /** @file AliHLTLogging.h |
9 | @author Matthias Richter, Timm Steinbeck | |
10 | @date | |
11 | @brief HLT module logging primitives. | |
12 | */ | |
3495cce2 | 13 | |
14 | #include "AliHLTDataTypes.h" | |
5f1685a0 | 15 | #include "AliHLTStdIncludes.h" |
fc455fba | 16 | #include "TObject.h" |
3495cce2 | 17 | |
85465857 | 18 | //#define LOG_PREFIX "" // logging prefix, for later extensions |
3495cce2 | 19 | |
85465857 | 20 | |
21 | /* the logging macros can be used inside methods of classes which inherit from | |
22 | * AliHLTLogging | |
23 | */ | |
24 | // HLTMessage is not filtered | |
fc455fba | 25 | #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ ) |
85465857 | 26 | |
fc455fba | 27 | // function name |
28 | #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__) | |
29 | #define FUNCTIONNAME() __FUNCTION__ | |
30 | #else | |
31 | #define FUNCTIONNAME() "???" | |
a4a8ef64 | 32 | #endif |
33 | ||
85465857 | 34 | // the following macros are filtered by the Global and Local Log Filter |
fc455fba | 35 | #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) |
36 | #define HLTDebug( ... ) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
37 | #define HLTInfo( ... ) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
38 | #define HLTWarning( ... ) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
39 | #define HLTError( ... ) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
40 | #define HLTFatal( ... ) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
85465857 | 41 | |
42 | // helper macro to set the keyword | |
70ed7d01 | 43 | #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey__LINE__(this, a) |
85465857 | 44 | |
45 | #define HLT_DEFAULT_LOG_KEYWORD "no key" | |
3495cce2 | 46 | |
47 | class AliHLTLogging { | |
48 | public: | |
49 | AliHLTLogging(); | |
85869391 | 50 | AliHLTLogging(const AliHLTLogging&); |
51 | AliHLTLogging& operator=(const AliHLTLogging&); | |
3495cce2 | 52 | virtual ~AliHLTLogging(); |
53 | ||
85465857 | 54 | // logging filter for all objects |
55 | // | |
8ede8717 | 56 | static AliHLTComponentLogSeverity SetGlobalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;} |
3495cce2 | 57 | |
85465857 | 58 | // logging filter for individual object |
59 | // | |
8ede8717 | 60 | AliHLTComponentLogSeverity SetLocalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;} |
85465857 | 61 | |
62 | // set the default key word | |
63 | // the keyword is intended to simplify the use of logging macros | |
64 | // | |
65 | void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; } | |
66 | ||
67 | // set a temporary keyword | |
68 | // returns the old key value | |
69 | const char* SetKeyword(const char* keyword) | |
70 | { | |
71 | const char* currentKeyword=fpCurrentKeyword; | |
72 | fpCurrentKeyword=keyword; | |
73 | return currentKeyword; | |
74 | } | |
75 | ||
76 | // get the current keyword | |
77 | // | |
85869391 | 78 | const char* GetKeyword() const |
85465857 | 79 | { |
80 | if (fpCurrentKeyword) return fpCurrentKeyword; | |
81 | else if (fpDefaultKeyword) return fpDefaultKeyword; | |
82 | return HLT_DEFAULT_LOG_KEYWORD; | |
83 | } | |
3495cce2 | 84 | |
bb16cc41 | 85 | static int Init(AliHLTfctLogging pFun); |
3495cce2 | 86 | |
87 | // genaral logging function | |
88 | // | |
8ede8717 | 89 | int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... ); |
3495cce2 | 90 | |
91 | // logging function with two origin parameters, used by the log macros | |
92 | // | |
fc455fba | 93 | int LoggingVarargs(AliHLTComponentLogSeverity severity, |
94 | const char* origin_class, const char* origin_func, | |
95 | const char* file, int line, ... ) const; | |
3495cce2 | 96 | |
97 | // apply filter, return 1 if message should pass | |
98 | // | |
8ede8717 | 99 | int CheckFilter(AliHLTComponentLogSeverity severity) const; |
3495cce2 | 100 | |
5f5b708b | 101 | // set global logging level |
102 | // | |
103 | static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level); | |
104 | ||
105 | // set local logging level | |
106 | // | |
107 | void SetLocalLoggingLevel(AliHLTComponentLogSeverity level); | |
108 | ||
fc455fba | 109 | /** |
110 | * Print message to stdout | |
111 | */ | |
8ede8717 | 112 | static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message); |
3495cce2 | 113 | |
fc455fba | 114 | #ifndef NOALIROOT_LOGGING |
115 | /** | |
116 | * Print message through AliRoot log channels. | |
117 | */ | |
118 | static int AliMessage(AliHLTComponentLogSeverity severity, | |
119 | const char* origin_class, const char* origin_func, | |
120 | const char* file, int line, const char* message); | |
121 | #endif | |
122 | ||
123 | /** | |
124 | * Build the log string from format specifier and variadac arguments | |
125 | * @param format format string of printf style | |
126 | * @param ap opened and initialized argument list | |
127 | * @return const char string with the formatted message | |
128 | */ | |
3495cce2 | 129 | static const char* BuildLogString(const char *format, va_list ap); |
130 | ||
131 | virtual void* GetParameter() {return NULL;} | |
fc455fba | 132 | |
133 | /** | |
134 | * Switch logging through AliLog on or off | |
135 | * @param sw 1 = logging through AliLog | |
136 | */ | |
137 | void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);} | |
138 | ||
3495cce2 | 139 | protected: |
140 | ||
141 | private: | |
fc455fba | 142 | /** the global logging filter */ |
143 | static AliHLTComponentLogSeverity fGlobalLogFilter; // see above | |
144 | /** the local logging filter for one class */ | |
145 | AliHLTComponentLogSeverity fLocalLogFilter; // see above | |
146 | /** logging callback from the framework */ | |
147 | static AliHLTfctLogging fLoggingFunc; // see above | |
148 | /** default keyword */ | |
149 | const char* fpDefaultKeyword; //! transient | |
150 | /** current keyword */ | |
151 | const char* fpCurrentKeyword; //! transient | |
152 | /** switch for logging through AliLog, default on */ | |
153 | static int fgUseAliLog; // see above | |
3495cce2 | 154 | |
3cde846d | 155 | ClassDef(AliHLTLogging, 1) |
3495cce2 | 156 | }; |
85465857 | 157 | |
158 | /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro | |
159 | * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class | |
160 | * the object is destroyed automatically when the current scope is left and so the keyword is set | |
161 | * to the original value | |
162 | */ | |
163 | class AliHLTKeyword { | |
164 | public: | |
165 | AliHLTKeyword() | |
85869391 | 166 | : |
167 | fpParent(NULL), | |
168 | fpOriginal(NULL) | |
85465857 | 169 | { |
85465857 | 170 | } |
171 | ||
172 | AliHLTKeyword(AliHLTLogging* parent, const char* keyword) | |
85869391 | 173 | : |
174 | fpParent(parent), | |
175 | fpOriginal(NULL) | |
85465857 | 176 | { |
85465857 | 177 | if (parent) { |
85465857 | 178 | fpOriginal=fpParent->SetKeyword(keyword); |
179 | } | |
180 | } | |
181 | ||
85869391 | 182 | AliHLTKeyword(const AliHLTKeyword& kw) |
183 | : | |
184 | fpParent(kw.fpParent), | |
185 | fpOriginal(kw.fpOriginal) | |
186 | { | |
187 | } | |
188 | ||
189 | AliHLTKeyword& operator=(const AliHLTKeyword& kw) | |
190 | { | |
191 | fpParent=kw.fpParent; | |
192 | fpOriginal=kw.fpOriginal; | |
193 | return *this; | |
194 | } | |
195 | ||
85465857 | 196 | ~AliHLTKeyword() |
197 | { | |
198 | if (fpParent) { | |
199 | fpParent->SetKeyword(fpOriginal); | |
200 | } | |
201 | } | |
202 | ||
203 | private: | |
204 | AliHLTLogging* fpParent; | |
205 | const char* fpOriginal; | |
206 | }; | |
3495cce2 | 207 | #endif |
208 |