]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTLogging.h
coding conventions
[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   static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
97
98   static const char* BuildLogString(const char *format, va_list ap);
99
100   virtual void* GetParameter() {return NULL;}
101 protected:
102
103 private:
104   static  AliHLTComponentLogSeverity fGlobalLogFilter;
105   AliHLTComponentLogSeverity fLocalLogFilter;
106   static AliHLTfctLogging fLoggingFunc;
107   const char* fpDefaultKeyword; //!
108   const char* fpCurrentKeyword; //!
109
110   ClassDef(AliHLTLogging, 1)
111 };
112
113 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
114  * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
115  * the object is destroyed automatically when the current scope is left and so the keyword is set
116  * to the original value
117  */
118 class AliHLTKeyword {
119  public:
120   AliHLTKeyword()
121     :
122     fpParent(NULL),
123     fpOriginal(NULL)
124     {
125     }
126
127   AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
128     :
129     fpParent(parent),
130     fpOriginal(NULL)
131     {
132       if (parent) {
133         fpOriginal=fpParent->SetKeyword(keyword);
134       }
135     }
136
137   AliHLTKeyword(const AliHLTKeyword& kw)
138     :
139     fpParent(kw.fpParent),
140     fpOriginal(kw.fpOriginal)
141     {
142     }
143
144   AliHLTKeyword& operator=(const AliHLTKeyword& kw)
145     { 
146       fpParent=kw.fpParent;
147       fpOriginal=kw.fpOriginal;
148       return *this;
149     }
150
151   ~AliHLTKeyword()
152     {
153       if (fpParent) {
154         fpParent->SetKeyword(fpOriginal);
155       }
156     }
157
158  private:
159   AliHLTLogging* fpParent;
160   const char* fpOriginal;
161 };
162 #endif
163