]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTLogging.h
Coding conventions
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.h
CommitLineData
fc455fba 1// @(#) $Id$
3495cce2 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
b22e91eb 8/** @file AliHLTLogging.h
9 @author Matthias Richter, Timm Steinbeck
10 @date
11 @brief HLT module logging primitives.
12*/
3495cce2 13
14#include "AliHLTDataTypes.h"
5f1685a0 15#include "AliHLTStdIncludes.h"
fc455fba 16#include "TObject.h"
66043029 17#include "TArrayC.h"
3495cce2 18
85465857 19//#define LOG_PREFIX "" // logging prefix, for later extensions
3495cce2 20
85465857 21
22/* the logging macros can be used inside methods of classes which inherit from
23 * AliHLTLogging
24 */
25// HLTMessage is not filtered
fc455fba 26#define HLTMessage( ... ) LoggingVarargs(kHLTLogNone, NULL , NULL , __FILE__ , __LINE__ , __VA_ARGS__ )
85465857 27
fc455fba 28// function name
29#if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
30#define FUNCTIONNAME() __FUNCTION__
31#else
32#define FUNCTIONNAME() "???"
a4a8ef64 33#endif
34
85465857 35// the following macros are filtered by the Global and Local Log Filter
fc455fba 36#define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
37#define HLTDebug( ... ) LoggingVarargs(kHLTLogDebug, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
38#define HLTInfo( ... ) LoggingVarargs(kHLTLogInfo, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
39#define HLTWarning( ... ) LoggingVarargs(kHLTLogWarning, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
40#define HLTError( ... ) LoggingVarargs(kHLTLogError, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
41#define HLTFatal( ... ) LoggingVarargs(kHLTLogFatal, Class_Name() , FUNCTIONNAME() , __FILE__ , __LINE__ , __VA_ARGS__ )
85465857 42
43// helper macro to set the keyword
70ed7d01 44#define HLTLogKeyword(a) AliHLTKeyword hltlogTmpkey__LINE__(this, a)
85465857 45
46#define HLT_DEFAULT_LOG_KEYWORD "no key"
3495cce2 47
48class AliHLTLogging {
49public:
50 AliHLTLogging();
85869391 51 AliHLTLogging(const AliHLTLogging&);
52 AliHLTLogging& operator=(const AliHLTLogging&);
3495cce2 53 virtual ~AliHLTLogging();
54
85465857 55 // set the default key word
56 // the keyword is intended to simplify the use of logging macros
57 //
58 void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
59
60 // set a temporary keyword
61 // returns the old key value
62 const char* SetKeyword(const char* keyword)
63 {
64 const char* currentKeyword=fpCurrentKeyword;
65 fpCurrentKeyword=keyword;
66 return currentKeyword;
67 }
68
69 // get the current keyword
70 //
85869391 71 const char* GetKeyword() const
85465857 72 {
73 if (fpCurrentKeyword) return fpCurrentKeyword;
74 else if (fpDefaultKeyword) return fpDefaultKeyword;
75 return HLT_DEFAULT_LOG_KEYWORD;
76 }
3495cce2 77
bb16cc41 78 static int Init(AliHLTfctLogging pFun);
3495cce2 79
80 // genaral logging function
81 //
8ede8717 82 int Logging( AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
3495cce2 83
84 // logging function with two origin parameters, used by the log macros
85 //
fc455fba 86 int LoggingVarargs(AliHLTComponentLogSeverity severity,
66043029 87 const char* originClass, const char* originFunc,
fc455fba 88 const char* file, int line, ... ) const;
3495cce2 89
90 // apply filter, return 1 if message should pass
91 //
8ede8717 92 int CheckFilter(AliHLTComponentLogSeverity severity) const;
3495cce2 93
5f5b708b 94 // set global logging level
d54f579e 95 // logging filter for all objects
5f5b708b 96 //
97 static void SetGlobalLoggingLevel(AliHLTComponentLogSeverity level);
98
99 // set local logging level
d54f579e 100 // logging filter for individual object
5f5b708b 101 //
102 void SetLocalLoggingLevel(AliHLTComponentLogSeverity level);
103
fc455fba 104 /**
105 * Print message to stdout
106 */
8ede8717 107 static int Message(void * param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message);
3495cce2 108
fc455fba 109#ifndef NOALIROOT_LOGGING
110 /**
111 * Print message through AliRoot log channels.
112 */
113 static int AliMessage(AliHLTComponentLogSeverity severity,
66043029 114 const char* originClass, const char* originFunc,
fc455fba 115 const char* file, int line, const char* message);
116#endif
117
118 /**
119 * Build the log string from format specifier and variadac arguments
120 * @param format format string of printf style
121 * @param ap opened and initialized argument list
122 * @return const char string with the formatted message
123 */
3495cce2 124 static const char* BuildLogString(const char *format, va_list ap);
125
66043029 126 /**
127 * Get parameter given by the external caller.
128 * This functionality is not yet implemented. It is intended
129 * to pass the parameter pointer given to the component at
130 * initialization back to the caller.
131 */
132 virtual void* GetParameter() const {return NULL;}
fc455fba 133
134 /**
135 * Switch logging through AliLog on or off
136 * @param sw 1 = logging through AliLog
137 */
138 void SwitchAliLog(int sw) {fgUseAliLog=(sw!=0);}
139
66043029 140 /** target stream for AliRoot logging methods */
141 static ostringstream fgLogstr; //! transient
142
3495cce2 143protected:
144
145private:
fc455fba 146 /** the global logging filter */
66043029 147 static AliHLTComponentLogSeverity fgGlobalLogFilter; // see above
fc455fba 148 /** the local logging filter for one class */
149 AliHLTComponentLogSeverity fLocalLogFilter; // see above
150 /** logging callback from the framework */
66043029 151 static AliHLTfctLogging fgLoggingFunc; // see above
fc455fba 152 /** default keyword */
153 const char* fpDefaultKeyword; //! transient
154 /** current keyword */
155 const char* fpCurrentKeyword; //! transient
156 /** switch for logging through AliLog, default on */
157 static int fgUseAliLog; // see above
66043029 158 /**
159 * The global logging buffer.
160 * The buffer is created with an initial size and grown dynamically on
161 * demand.
162 */
163 static TArrayC fgAliHLTLoggingTarget; //! transient
164
165 /** the maximum size of the buffer */
166 static const int fgkALIHLTLOGGINGMAXBUFFERSIZE; //! transient
3495cce2 167
66043029 168 ClassDef(AliHLTLogging, 2)
3495cce2 169};
85465857 170
171/* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
172 * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
173 * the object is destroyed automatically when the current scope is left and so the keyword is set
174 * to the original value
175 */
176class AliHLTKeyword {
177 public:
178 AliHLTKeyword()
85869391 179 :
180 fpParent(NULL),
181 fpOriginal(NULL)
85465857 182 {
85465857 183 }
184
185 AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
85869391 186 :
187 fpParent(parent),
188 fpOriginal(NULL)
85465857 189 {
85465857 190 if (parent) {
85465857 191 fpOriginal=fpParent->SetKeyword(keyword);
192 }
193 }
194
85869391 195 AliHLTKeyword(const AliHLTKeyword& kw)
196 :
197 fpParent(kw.fpParent),
198 fpOriginal(kw.fpOriginal)
199 {
200 }
201
202 AliHLTKeyword& operator=(const AliHLTKeyword& kw)
203 {
204 fpParent=kw.fpParent;
205 fpOriginal=kw.fpOriginal;
206 return *this;
207 }
208
85465857 209 ~AliHLTKeyword()
210 {
211 if (fpParent) {
212 fpParent->SetKeyword(fpOriginal);
213 }
214 }
215
216 private:
66043029 217 AliHLTLogging* fpParent; //! transient
218 const char* fpOriginal; //! transient
85465857 219};
3495cce2 220#endif
221