]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTLogging.h
cf0d446e71686357e52b1f8175bb2e907399f84b
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.h
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 <TObject.h>
16 #include "AliHLTStdIncludes.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 ,  __VA_ARGS__ )
26
27 #ifndef __func__
28 #define __func__ "???"
29 #endif
30
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
40 #define HLTLogKeyword(a)    AliHLTKeyword hltlogTmpkey__LINE__(this, a)
41
42 #define HLT_DEFAULT_LOG_KEYWORD "no key"
43
44 class AliHLTLogging {
45 public:
46   AliHLTLogging();
47   AliHLTLogging(const AliHLTLogging&);
48   AliHLTLogging& operator=(const AliHLTLogging&);
49   virtual ~AliHLTLogging();
50
51   // logging filter for all objects
52   //
53   static AliHLTComponentLogSeverity SetGlobalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
54
55   // logging filter for individual object
56   //
57   AliHLTComponentLogSeverity SetLocalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
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   //
75   const char* GetKeyword() const
76     {
77       if (fpCurrentKeyword) return fpCurrentKeyword;
78       else if (fpDefaultKeyword) return fpDefaultKeyword;
79       return HLT_DEFAULT_LOG_KEYWORD;
80     }
81   
82   static int Init(AliHLTfctLogging pFun);
83
84   // genaral logging function
85   //
86   int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
87
88   // logging function with two origin parameters, used by the log macros
89   //
90   int LoggingVarargs( AliHLTComponentLogSeverity severity, const char* origin_class, const char* origin_func,  ... ) const;
91
92   // apply filter, return 1 if message should pass
93   //
94   int CheckFilter(AliHLTComponentLogSeverity severity) const;
95
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
104   static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
105
106   static const char* BuildLogString(const char *format, va_list ap);
107
108   virtual void* GetParameter() {return NULL;}
109 protected:
110
111 private:
112   static  AliHLTComponentLogSeverity fGlobalLogFilter;
113   AliHLTComponentLogSeverity fLocalLogFilter;
114   static AliHLTfctLogging fLoggingFunc;
115   const char* fpDefaultKeyword; //!
116   const char* fpCurrentKeyword; //!
117
118   ClassDef(AliHLTLogging, 1)
119 };
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()
129     :
130     fpParent(NULL),
131     fpOriginal(NULL)
132     {
133     }
134
135   AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
136     :
137     fpParent(parent),
138     fpOriginal(NULL)
139     {
140       if (parent) {
141         fpOriginal=fpParent->SetKeyword(keyword);
142       }
143     }
144
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
159   ~AliHLTKeyword()
160     {
161       if (fpParent) {
162         fpParent->SetKeyword(fpOriginal);
163       }
164     }
165
166  private:
167   AliHLTLogging* fpParent;
168   const char* fpOriginal;
169 };
170 #endif
171