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