]>
Commit | Line | Data |
---|---|---|
3495cce2 | 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 | ||
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" | |
15 | #include <TObject.h> | |
5f1685a0 | 16 | #include "AliHLTStdIncludes.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 | |
25 | #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __VA_ARGS__ ) | |
26 | ||
a4a8ef64 | 27 | #ifndef __func__ |
28 | #define __func__ "???" | |
29 | #endif | |
30 | ||
85465857 | 31 | // the following macros are filtered by the Global and Local Log Filter |
32 | #define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, this->Class_Name() , __func__ , __VA_ARGS__ ) | |
33 | #define HLTDebug( ... ) LoggingVarargs(kHLTLogDebug, this->Class_Name() , __func__ , __VA_ARGS__ ) | |
34 | #define HLTInfo( ... ) LoggingVarargs(kHLTLogInfo, this->Class_Name() , __func__ , __VA_ARGS__ ) | |
35 | #define HLTWarning( ... ) LoggingVarargs(kHLTLogWarning, this->Class_Name() , __func__ , __VA_ARGS__ ) | |
36 | #define HLTError( ... ) LoggingVarargs(kHLTLogError, this->Class_Name() , __func__ , __VA_ARGS__ ) | |
37 | #define HLTFatal( ... ) LoggingVarargs(kHLTLogFatal, this->Class_Name() , __func__ , __VA_ARGS__ ) | |
38 | ||
39 | // helper macro to set the keyword | |
70ed7d01 | 40 | #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey__LINE__(this, a) |
85465857 | 41 | |
42 | #define HLT_DEFAULT_LOG_KEYWORD "no key" | |
3495cce2 | 43 | |
44 | class AliHLTLogging { | |
45 | public: | |
46 | AliHLTLogging(); | |
85869391 | 47 | AliHLTLogging(const AliHLTLogging&); |
48 | AliHLTLogging& operator=(const AliHLTLogging&); | |
3495cce2 | 49 | virtual ~AliHLTLogging(); |
50 | ||
85465857 | 51 | // logging filter for all objects |
52 | // | |
8ede8717 | 53 | static AliHLTComponentLogSeverity SetGlobalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;} |
3495cce2 | 54 | |
85465857 | 55 | // logging filter for individual object |
56 | // | |
8ede8717 | 57 | AliHLTComponentLogSeverity SetLocalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;} |
85465857 | 58 | |
59 | // set the default key word | |
60 | // the keyword is intended to simplify the use of logging macros | |
61 | // | |
62 | void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; } | |
63 | ||
64 | // set a temporary keyword | |
65 | // returns the old key value | |
66 | const char* SetKeyword(const char* keyword) | |
67 | { | |
68 | const char* currentKeyword=fpCurrentKeyword; | |
69 | fpCurrentKeyword=keyword; | |
70 | return currentKeyword; | |
71 | } | |
72 | ||
73 | // get the current keyword | |
74 | // | |
85869391 | 75 | const char* GetKeyword() const |
85465857 | 76 | { |
77 | if (fpCurrentKeyword) return fpCurrentKeyword; | |
78 | else if (fpDefaultKeyword) return fpDefaultKeyword; | |
79 | return HLT_DEFAULT_LOG_KEYWORD; | |
80 | } | |
3495cce2 | 81 | |
bb16cc41 | 82 | static int Init(AliHLTfctLogging pFun); |
3495cce2 | 83 | |
84 | // genaral logging function | |
85 | // | |
8ede8717 | 86 | int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... ); |
3495cce2 | 87 | |
88 | // logging function with two origin parameters, used by the log macros | |
89 | // | |
8ede8717 | 90 | int LoggingVarargs( AliHLTComponentLogSeverity severity, const char* origin_class, const char* origin_func, ... ) const; |
3495cce2 | 91 | |
92 | // apply filter, return 1 if message should pass | |
93 | // | |
8ede8717 | 94 | int CheckFilter(AliHLTComponentLogSeverity severity) const; |
3495cce2 | 95 | |
5f5b708b | 96 | // set global logging level |
97 | // | |
98 | static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level); | |
99 | ||
100 | // set local logging level | |
101 | // | |
102 | void SetLocalLoggingLevel(AliHLTComponentLogSeverity level); | |
103 | ||
8ede8717 | 104 | static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message); |
3495cce2 | 105 | |
106 | static const char* BuildLogString(const char *format, va_list ap); | |
107 | ||
108 | virtual void* GetParameter() {return NULL;} | |
109 | protected: | |
110 | ||
111 | private: | |
8ede8717 | 112 | static AliHLTComponentLogSeverity fGlobalLogFilter; |
113 | AliHLTComponentLogSeverity fLocalLogFilter; | |
5ec8e281 | 114 | static AliHLTfctLogging fLoggingFunc; |
3cde846d | 115 | const char* fpDefaultKeyword; //! |
116 | const char* fpCurrentKeyword; //! | |
3495cce2 | 117 | |
3cde846d | 118 | ClassDef(AliHLTLogging, 1) |
3495cce2 | 119 | }; |
85465857 | 120 | |
121 | /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro | |
122 | * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class | |
123 | * the object is destroyed automatically when the current scope is left and so the keyword is set | |
124 | * to the original value | |
125 | */ | |
126 | class AliHLTKeyword { | |
127 | public: | |
128 | AliHLTKeyword() | |
85869391 | 129 | : |
130 | fpParent(NULL), | |
131 | fpOriginal(NULL) | |
85465857 | 132 | { |
85465857 | 133 | } |
134 | ||
135 | AliHLTKeyword(AliHLTLogging* parent, const char* keyword) | |
85869391 | 136 | : |
137 | fpParent(parent), | |
138 | fpOriginal(NULL) | |
85465857 | 139 | { |
85465857 | 140 | if (parent) { |
85465857 | 141 | fpOriginal=fpParent->SetKeyword(keyword); |
142 | } | |
143 | } | |
144 | ||
85869391 | 145 | AliHLTKeyword(const AliHLTKeyword& kw) |
146 | : | |
147 | fpParent(kw.fpParent), | |
148 | fpOriginal(kw.fpOriginal) | |
149 | { | |
150 | } | |
151 | ||
152 | AliHLTKeyword& operator=(const AliHLTKeyword& kw) | |
153 | { | |
154 | fpParent=kw.fpParent; | |
155 | fpOriginal=kw.fpOriginal; | |
156 | return *this; | |
157 | } | |
158 | ||
85465857 | 159 | ~AliHLTKeyword() |
160 | { | |
161 | if (fpParent) { | |
162 | fpParent->SetKeyword(fpOriginal); | |
163 | } | |
164 | } | |
165 | ||
166 | private: | |
167 | AliHLTLogging* fpParent; | |
168 | const char* fpOriginal; | |
169 | }; | |
3495cce2 | 170 | #endif |
171 |