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"
18 #define LOG_BUFFER_SIZE 100 // global logging buffer
19 //#define LOG_PREFIX "" // logging prefix, for later extensions
22 /* the logging macros can be used inside methods of classes which inherit from
25 // HLTMessage is not filtered
26 #define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __VA_ARGS__ )
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__ )
36 // helper macro to set the keyword
37 #define HLTLogKeyword(a) AliHLTKeyword __hltlog_tmpkey__LINE__(this, a)
39 #define HLT_DEFAULT_LOG_KEYWORD "no key"
44 virtual ~AliHLTLogging();
46 // logging filter for all objects
48 static AliHLTComponent_LogSeverity SetGlobalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
50 // logging filter for individual object
52 AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
54 // set the default key word
55 // the keyword is intended to simplify the use of logging macros
57 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
59 // set a temporary keyword
60 // returns the old key value
61 const char* SetKeyword(const char* keyword)
63 const char* currentKeyword=fpCurrentKeyword;
64 fpCurrentKeyword=keyword;
65 return currentKeyword;
68 // get the current keyword
70 const char* GetKeyword()
72 if (fpCurrentKeyword) return fpCurrentKeyword;
73 else if (fpDefaultKeyword) return fpDefaultKeyword;
74 return HLT_DEFAULT_LOG_KEYWORD;
77 static int Init(AliHLTfctLogging pFun);
79 // genaral logging function
81 int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
83 // logging function with two origin parameters, used by the log macros
85 int LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func, ... );
87 // apply filter, return 1 if message should pass
89 int CheckFilter(AliHLTComponent_LogSeverity severity);
91 static int Message(void * param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message);
93 static const char* BuildLogString(const char *format, va_list ap);
95 virtual void* GetParameter() {return NULL;}
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;
107 ClassDef(AliHLTLogging, 0)
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
115 class AliHLTKeyword {
123 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
128 fpOriginal=fpParent->SetKeyword(keyword);
135 fpParent->SetKeyword(fpOriginal);
140 AliHLTLogging* fpParent;
141 const char* fpOriginal;