]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTLogging.cxx
Legend in the display corrected
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.cxx
CommitLineData
3495cce2 1// $Id:
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
3495cce2 8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
b22e91eb 19/** @file AliHLTLogging.cxx
20 @author Matthias Richter, Timm Steinbeck
21 @date
22 @brief Implementation of HLT logging primitives.
23*/
3495cce2 24
0c0c9d99 25#if __GNUC__>= 3
3495cce2 26using namespace std;
27#endif
28
85869391 29#include "AliHLTStdIncludes.h"
3495cce2 30#include "AliHLTLogging.h"
3cde846d 31#include "TString.h"
3495cce2 32
5f1685a0 33// global logging buffer
b648d8df 34#define LOG_BUFFER_SIZE 512
5f1685a0 35char gAliHLTLoggingBuffer[LOG_BUFFER_SIZE]="";
36char gAliHLTLoggingOriginBuffer[LOG_BUFFER_SIZE]="";
37
b22e91eb 38/** ROOT macro for the implementation of ROOT specific class methods */
3495cce2 39ClassImp(AliHLTLogging)
40
3495cce2 41AliHLTLogging::AliHLTLogging()
85869391 42 :
85869391 43 //fLocalLogFilter(kHLTLogDefault),
53feaef5 44 fLocalLogFilter(kHLTLogAll),
45 fpDefaultKeyword(NULL),
46 fpCurrentKeyword(NULL)
3495cce2 47{
5f5b708b 48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85869391 53}
54
55AliHLTLogging::AliHLTLogging(const AliHLTLogging&)
56 :
53feaef5 57 fLocalLogFilter(kHLTLogAll),
85869391 58 fpDefaultKeyword(NULL),
53feaef5 59 fpCurrentKeyword(NULL)
85869391 60{
5f5b708b 61 // see header file for class documentation
85869391 62 HLTFatal("copy constructor untested");
63}
64
65AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&)
66{
5f5b708b 67 // see header file for class documentation
85869391 68 HLTFatal("assignment operator untested");
69 return *this;
3495cce2 70}
71
8ede8717 72AliHLTComponentLogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll;
b22e91eb 73AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL;
3495cce2 74
75AliHLTLogging::~AliHLTLogging()
76{
5f5b708b 77 // see header file for class documentation
3495cce2 78}
79
bb16cc41 80int AliHLTLogging::Init(AliHLTfctLogging pFun)
81{
5f5b708b 82 // see header file for class documentation
bb16cc41 83 if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) {
84 (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
85 }
86 fLoggingFunc=pFun;
87 return 0;
88}
89
5f5b708b 90int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message)
91{
92 // see header file for class documentation
3495cce2 93 int iResult=0;
53feaef5 94 if (param==NULL) {
95 // this is currently just to get rid of the warning "unused parameter"
96 }
3495cce2 97 const char* strSeverity="";
98 switch (severity) {
99 case kHLTLogBenchmark:
100 strSeverity="benchmark";
101 break;
102 case kHLTLogDebug:
103 strSeverity="debug";
104 break;
105 case kHLTLogInfo:
106 strSeverity="info";
107 break;
108 case kHLTLogWarning:
109 strSeverity="warning";
110 break;
111 case kHLTLogError:
112 strSeverity="error";
113 break;
114 case kHLTLogFatal:
115 strSeverity="fatal";
116 break;
117 default:
118 break;
119 }
3cde846d 120 TString out="HLT Log ";
121 out+=strSeverity;
122 if (origin) {out+=": "; out+=origin;}
123 out+=" "; out+=message;
124 if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) {
125 out+=" ("; out+=keyword; out +=")";
126 }
127 cout << out.Data() << endl;
3495cce2 128 return iResult;
129}
130
5f5b708b 131const char* AliHLTLogging::BuildLogString(const char *format, va_list ap)
132{
133 // see header file for class documentation
3495cce2 134 int tgtLen=0;
135 int iBufferSize=LOG_BUFFER_SIZE;
5f1685a0 136 char* tgtBuffer=gAliHLTLoggingBuffer;
3495cce2 137 tgtBuffer[tgtLen]=0;
138
85465857 139#if (defined LOG_PREFIX)
3495cce2 140 tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix
85465857 141#endif
3495cce2 142 if (tgtLen>=0) {
143 tgtBuffer+=tgtLen; iBufferSize-=tgtLen;
144 tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap);
145 if (tgtLen>0) {
146 tgtBuffer+=tgtLen;
147// if (tgtLen<LOG_BUFFER_SIZE-1) {
148// *tgtBuffer++='\n'; // add newline if space in buffer
149// }
150 *tgtBuffer=0; // terminate the buffer
151 }
152 }
5f1685a0 153 return gAliHLTLoggingBuffer;
3495cce2 154}
155
5f5b708b 156int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* format, ... )
157{
158 // see header file for class documentation
85465857 159 int iResult=CheckFilter(severity);
160 if (iResult>0) {
161 va_list args;
162 va_start(args, format);
163 if (fLoggingFunc) {
164 iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
165 } else {
166 iResult = Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
167 }
3495cce2 168 }
85465857 169 return iResult;
3495cce2 170}
171
8ede8717 172int AliHLTLogging::LoggingVarargs( AliHLTComponentLogSeverity severity, const char* origin_class, const char* origin_func, ... ) const
3495cce2 173{
5f5b708b 174 // see header file for class documentation
175
85465857 176 int iResult=CheckFilter(severity);
177 if (iResult>0) {
178 int iMaxSize=LOG_BUFFER_SIZE-1;
179 int iPos=0;
180 const char* separator="";
5f1685a0 181 gAliHLTLoggingOriginBuffer[iPos]=0;
85465857 182 if (origin_class) {
183 if ((int)strlen(origin_class)<iMaxSize-iPos) {
5f1685a0 184 strcpy(&gAliHLTLoggingOriginBuffer[iPos], origin_class);
85465857 185 iPos+=strlen(origin_class);
186 separator="::";
187 }
3495cce2 188 }
85465857 189 if (origin_func) {
190 if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) {
5f1685a0 191 strcpy(&gAliHLTLoggingOriginBuffer[iPos], separator);
85465857 192 iPos+=strlen(separator);
5f1685a0 193 strcpy(&gAliHLTLoggingOriginBuffer[iPos], origin_func);
85465857 194 iPos+=strlen(origin_func);
195 }
3495cce2 196 }
85465857 197 va_list args;
198 va_start(args, origin_func);
199 const char* format = va_arg(args, const char*);
200
201 const char* message=format;
8b250b0e 202 const char* qualifier=NULL;
85465857 203 if ((qualifier=strchr(format, '%'))!=NULL) {
204 message=AliHLTLogging::BuildLogString(format, args);
205 }
206 if (fLoggingFunc) {
5f1685a0 207 iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, gAliHLTLoggingOriginBuffer, GetKeyword(), message);
85465857 208 } else {
5f1685a0 209 iResult=Message(NULL/*fParam*/, severity, gAliHLTLoggingOriginBuffer, GetKeyword(), message);
85465857 210 }
211 va_end(args);
3495cce2 212 }
3495cce2 213 return iResult;
214}
215
8ede8717 216int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const
3495cce2 217{
5f5b708b 218 // see header file for class documentation
219
85465857 220 int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
3495cce2 221 return iResult;
222}
5f5b708b 223
224void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level)
225{
226 // see header file for class documentation
227
228 fGlobalLogFilter=level;
229}
230
231void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
232{
233 // see header file for class documentation
234
235 fLocalLogFilter=level;
236}