]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTLogging.h
added code documentation for BASE, SampleLib, TPCLib and build system
[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 <stdio.h>
17
18 #define LOG_BUFFER_SIZE 100 // global logging buffer
19 //#define LOG_PREFIX ""       // logging prefix, for later extensions
20
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"
40
41 class AliHLTLogging {
42 public:
43   AliHLTLogging();
44   virtual ~AliHLTLogging();
45
46   // logging filter for all objects
47   //
48   static AliHLTComponent_LogSeverity SetGlobalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
49
50   // logging filter for individual object
51   //
52   AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
53
54   // set the default key word
55   // the keyword is intended to simplify the use of logging macros
56   // 
57   void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
58
59   // set a temporary keyword
60   // returns the old key value
61   const char* SetKeyword(const char* keyword) 
62     { 
63       const char* currentKeyword=fpCurrentKeyword;
64       fpCurrentKeyword=keyword;
65       return currentKeyword; 
66     }
67
68   // get the current keyword
69   //
70   const char* GetKeyword()
71     {
72       if (fpCurrentKeyword) return fpCurrentKeyword;
73       else if (fpDefaultKeyword) return fpDefaultKeyword;
74       return HLT_DEFAULT_LOG_KEYWORD;
75     }
76   
77   static int Init(AliHLTfctLogging pFun);
78
79   // genaral logging function
80   //
81   int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
82
83   // logging function with two origin parameters, used by the log macros
84   //
85   int LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func,  ... );
86
87   // apply filter, return 1 if message should pass
88   //
89   int CheckFilter(AliHLTComponent_LogSeverity severity);
90
91   static int Message(void * param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message);
92
93   static const char* BuildLogString(const char *format, va_list ap);
94
95   virtual void* GetParameter() {return NULL;}
96 protected:
97
98 private:
99   static  AliHLTComponent_LogSeverity fGlobalLogFilter;
100   AliHLTComponent_LogSeverity fLocalLogFilter;
101   static char fLogBuffer[LOG_BUFFER_SIZE];
102   static char fOriginBuffer[LOG_BUFFER_SIZE];
103   static AliHLTfctLogging fLoggingFunc;
104   const char* fpDefaultKeyword;
105   const char* fpCurrentKeyword;
106
107   ClassDef(AliHLTLogging, 0)
108 };
109
110 /* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
111  * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
112  * the object is destroyed automatically when the current scope is left and so the keyword is set
113  * to the original value
114  */
115 class AliHLTKeyword {
116  public:
117   AliHLTKeyword()
118     {
119       fpParent=NULL;
120       fpOriginal=NULL;
121     }
122
123   AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
124     {
125       fpOriginal=NULL;
126       if (parent) {
127         fpParent=parent;
128         fpOriginal=fpParent->SetKeyword(keyword);
129       }
130     }
131
132   ~AliHLTKeyword()
133     {
134       if (fpParent) {
135         fpParent->SetKeyword(fpOriginal);
136       }
137     }
138
139  private:
140   AliHLTLogging* fpParent;
141   const char* fpOriginal;
142 };
143 #endif
144