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 */
8 /** @file AliHLTLogging.h
9 @author Matthias Richter, Timm Steinbeck
11 @brief HLT module logging primitives.
14 #include "AliHLTDataTypes.h"
16 #include "AliHLTStdIncludes.h"
18 //#define LOG_PREFIX "" // logging prefix, for later extensions
21 /* the logging macros can be used inside methods of classes which inherit from
24 // HLTMessage is not filtered
25 #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __VA_ARGS__ )
28 #define __func__ "???"
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__ )
39 // helper macro to set the keyword
40 #define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey__LINE__(this, a)
42 #define HLT_DEFAULT_LOG_KEYWORD "no key"
47 AliHLTLogging(const AliHLTLogging&);
48 AliHLTLogging& operator=(const AliHLTLogging&);
49 virtual ~AliHLTLogging();
51 // logging filter for all objects
53 static AliHLTComponentLogSeverity SetGlobalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
55 // logging filter for individual object
57 AliHLTComponentLogSeverity SetLocalLogLevel(AliHLTComponentLogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
59 // set the default key word
60 // the keyword is intended to simplify the use of logging macros
62 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
64 // set a temporary keyword
65 // returns the old key value
66 const char* SetKeyword(const char* keyword)
68 const char* currentKeyword=fpCurrentKeyword;
69 fpCurrentKeyword=keyword;
70 return currentKeyword;
73 // get the current keyword
75 const char* GetKeyword() const
77 if (fpCurrentKeyword) return fpCurrentKeyword;
78 else if (fpDefaultKeyword) return fpDefaultKeyword;
79 return HLT_DEFAULT_LOG_KEYWORD;
82 static int Init(AliHLTfctLogging pFun);
84 // genaral logging function
86 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
88 // logging function with two origin parameters, used by the log macros
90 int LoggingVarargs( AliHLTComponentLogSeverity severity, const char* origin_class, const char* origin_func, ... ) const;
92 // apply filter, return 1 if message should pass
94 int CheckFilter(AliHLTComponentLogSeverity severity) const;
96 // set global logging level
98 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
100 // set local logging level
102 void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
104 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
106 static const char* BuildLogString(const char *format, va_list ap);
108 virtual void* GetParameter() {return NULL;}
112 static AliHLTComponentLogSeverity fGlobalLogFilter;
113 AliHLTComponentLogSeverity fLocalLogFilter;
114 static AliHLTfctLogging fLoggingFunc;
115 const char* fpDefaultKeyword; //!
116 const char* fpCurrentKeyword; //!
118 ClassDef(AliHLTLogging, 1)
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
126 class AliHLTKeyword {
135 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
141 fpOriginal=fpParent->SetKeyword(keyword);
145 AliHLTKeyword(const AliHLTKeyword& kw)
147 fpParent(kw.fpParent),
148 fpOriginal(kw.fpOriginal)
152 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
154 fpParent=kw.fpParent;
155 fpOriginal=kw.fpOriginal;
162 fpParent->SetKeyword(fpOriginal);
167 AliHLTLogging* fpParent;
168 const char* fpOriginal;