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