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__ )
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__ )
35 // helper macro to set the keyword
36 #define HLTLogKeyword(a) AliHLTKeyword __hltlog_tmpkey__LINE__(this, a)
38 #define HLT_DEFAULT_LOG_KEYWORD "no key"
43 AliHLTLogging(const AliHLTLogging&);
44 AliHLTLogging& operator=(const AliHLTLogging&);
45 virtual ~AliHLTLogging();
47 // logging filter for all objects
49 static AliHLTComponent_LogSeverity SetGlobalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
51 // logging filter for individual object
53 AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
55 // set the default key word
56 // the keyword is intended to simplify the use of logging macros
58 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
60 // set a temporary keyword
61 // returns the old key value
62 const char* SetKeyword(const char* keyword)
64 const char* currentKeyword=fpCurrentKeyword;
65 fpCurrentKeyword=keyword;
66 return currentKeyword;
69 // get the current keyword
71 const char* GetKeyword() const
73 if (fpCurrentKeyword) return fpCurrentKeyword;
74 else if (fpDefaultKeyword) return fpDefaultKeyword;
75 return HLT_DEFAULT_LOG_KEYWORD;
78 static int Init(AliHLTfctLogging pFun);
80 // genaral logging function
82 int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
84 // logging function with two origin parameters, used by the log macros
86 int LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func, ... ) const;
88 // apply filter, return 1 if message should pass
90 int CheckFilter(AliHLTComponent_LogSeverity severity) const;
92 static int Message(void * param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message);
94 static const char* BuildLogString(const char *format, va_list ap);
96 virtual void* GetParameter() {return NULL;}
100 static AliHLTComponent_LogSeverity fGlobalLogFilter;
101 AliHLTComponent_LogSeverity fLocalLogFilter;
102 static AliHLTfctLogging fLoggingFunc;
103 const char* fpDefaultKeyword;
104 const char* fpCurrentKeyword;
106 ClassDef(AliHLTLogging, 0)
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
114 class AliHLTKeyword {
123 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
129 fpOriginal=fpParent->SetKeyword(keyword);
133 AliHLTKeyword(const AliHLTKeyword& kw)
135 fpParent(kw.fpParent),
136 fpOriginal(kw.fpOriginal)
140 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
142 fpParent=kw.fpParent;
143 fpOriginal=kw.fpOriginal;
150 fpParent->SetKeyword(fpOriginal);
155 AliHLTLogging* fpParent;
156 const char* fpOriginal;