]>
Commit | Line | Data |
---|---|---|
1 | // @(#) $Id$ | |
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 | ||
8 | /** @file AliHLTLogging.h | |
9 | @author Matthias Richter, Timm Steinbeck | |
10 | @date | |
11 | @brief HLT module logging primitives. | |
12 | */ | |
13 | ||
14 | #include "AliHLTDataTypes.h" | |
15 | #include "AliHLTStdIncludes.h" | |
16 | #include "TObject.h" | |
17 | ||
18 | //#define LOG_PREFIX "" // logging prefix, for later extensions | |
19 | ||
20 | ||
21 | /* the logging macros can be used inside methods of classes which inherit from | |
22 | * AliHLTLogging | |
23 | */ | |
24 | // HLTMessage is not filtered | |
25 | #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ ) | |
26 | ||
27 | // function name | |
28 | #if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__) | |
29 | #define FUNCTIONNAME() __FUNCTION__ | |
30 | #else | |
31 | #define FUNCTIONNAME() "???" | |
32 | #endif | |
33 | ||
34 | // the following macros are filtered by the Global and Local Log Filter | |
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__ ) | |
41 | ||
42 | // helper macro to set the keyword | |
43 | #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey__LINE__(this, a) | |
44 | ||
45 | #define HLT_DEFAULT_LOG_KEYWORD "no key" | |
46 | ||
47 | class AliHLTLogging { | |
48 | public: | |
49 | AliHLTLogging(); | |
50 | AliHLTLogging(const AliHLTLogging&); | |
51 | AliHLTLogging& operator=(const AliHLTLogging&); | |
52 | virtual ~AliHLTLogging(); | |
53 | ||
54 | // logging filter for all objects | |
55 | // | |
56 | static AliHLTComponentLogSeverity SetGlobalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;} | |
57 | ||
58 | // logging filter for individual object | |
59 | // | |
60 | AliHLTComponentLogSeverity SetLocalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;} | |
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 | // | |
78 | const char* GetKeyword() const | |
79 | { | |
80 | if (fpCurrentKeyword) return fpCurrentKeyword; | |
81 | else if (fpDefaultKeyword) return fpDefaultKeyword; | |
82 | return HLT_DEFAULT_LOG_KEYWORD; | |
83 | } | |
84 | ||
85 | static int Init(AliHLTfctLogging pFun); | |
86 | ||
87 | // genaral logging function | |
88 | // | |
89 | int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... ); | |
90 | ||
91 | // logging function with two origin parameters, used by the log macros | |
92 | // | |
93 | int LoggingVarargs(AliHLTComponentLogSeverity severity, | |
94 | const char* origin_class, const char* origin_func, | |
95 | const char* file, int line, ... ) const; | |
96 | ||
97 | // apply filter, return 1 if message should pass | |
98 | // | |
99 | int CheckFilter(AliHLTComponentLogSeverity severity) const; | |
100 | ||
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 | ||
109 | /** | |
110 | * Print message to stdout | |
111 | */ | |
112 | static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message); | |
113 | ||
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 | */ | |
129 | static const char* BuildLogString(const char *format, va_list ap); | |
130 | ||
131 | virtual void* GetParameter() {return NULL;} | |
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 | ||
139 | protected: | |
140 | ||
141 | private: | |
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 | |
154 | ||
155 | ClassDef(AliHLTLogging, 1) | |
156 | }; | |
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() | |
166 | : | |
167 | fpParent(NULL), | |
168 | fpOriginal(NULL) | |
169 | { | |
170 | } | |
171 | ||
172 | AliHLTKeyword(AliHLTLogging* parent, const char* keyword) | |
173 | : | |
174 | fpParent(parent), | |
175 | fpOriginal(NULL) | |
176 | { | |
177 | if (parent) { | |
178 | fpOriginal=fpParent->SetKeyword(keyword); | |
179 | } | |
180 | } | |
181 | ||
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 | ||
196 | ~AliHLTKeyword() | |
197 | { | |
198 | if (fpParent) { | |
199 | fpParent->SetKeyword(fpOriginal); | |
200 | } | |
201 | } | |
202 | ||
203 | private: | |
204 | AliHLTLogging* fpParent; | |
205 | const char* fpOriginal; | |
206 | }; | |
207 | #endif | |
208 |