]>
Commit | Line | Data |
---|---|---|
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 | 26 | using 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 | 35 | char gAliHLTLoggingBuffer[LOG_BUFFER_SIZE]=""; |
36 | char gAliHLTLoggingOriginBuffer[LOG_BUFFER_SIZE]=""; | |
37 | ||
b22e91eb | 38 | /** ROOT macro for the implementation of ROOT specific class methods */ |
3495cce2 | 39 | ClassImp(AliHLTLogging) |
40 | ||
3495cce2 | 41 | AliHLTLogging::AliHLTLogging() |
85869391 | 42 | : |
85869391 | 43 | //fLocalLogFilter(kHLTLogDefault), |
53feaef5 | 44 | fLocalLogFilter(kHLTLogAll), |
45 | fpDefaultKeyword(NULL), | |
46 | fpCurrentKeyword(NULL) | |
3495cce2 | 47 | { |
85869391 | 48 | } |
49 | ||
50 | AliHLTLogging::AliHLTLogging(const AliHLTLogging&) | |
51 | : | |
53feaef5 | 52 | fLocalLogFilter(kHLTLogAll), |
85869391 | 53 | fpDefaultKeyword(NULL), |
53feaef5 | 54 | fpCurrentKeyword(NULL) |
85869391 | 55 | { |
56 | HLTFatal("copy constructor untested"); | |
57 | } | |
58 | ||
59 | AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&) | |
60 | { | |
61 | HLTFatal("assignment operator untested"); | |
62 | return *this; | |
3495cce2 | 63 | } |
64 | ||
8ede8717 | 65 | AliHLTComponentLogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll; |
b22e91eb | 66 | AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL; |
3495cce2 | 67 | |
68 | AliHLTLogging::~AliHLTLogging() | |
69 | { | |
70 | } | |
71 | ||
bb16cc41 | 72 | int AliHLTLogging::Init(AliHLTfctLogging pFun) |
73 | { | |
74 | if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) { | |
75 | (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function"); | |
76 | } | |
77 | fLoggingFunc=pFun; | |
78 | return 0; | |
79 | } | |
80 | ||
8ede8717 | 81 | int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* message) { |
3495cce2 | 82 | int iResult=0; |
53feaef5 | 83 | if (param==NULL) { |
84 | // this is currently just to get rid of the warning "unused parameter" | |
85 | } | |
3495cce2 | 86 | const char* strSeverity=""; |
87 | switch (severity) { | |
88 | case kHLTLogBenchmark: | |
89 | strSeverity="benchmark"; | |
90 | break; | |
91 | case kHLTLogDebug: | |
92 | strSeverity="debug"; | |
93 | break; | |
94 | case kHLTLogInfo: | |
95 | strSeverity="info"; | |
96 | break; | |
97 | case kHLTLogWarning: | |
98 | strSeverity="warning"; | |
99 | break; | |
100 | case kHLTLogError: | |
101 | strSeverity="error"; | |
102 | break; | |
103 | case kHLTLogFatal: | |
104 | strSeverity="fatal"; | |
105 | break; | |
106 | default: | |
107 | break; | |
108 | } | |
3cde846d | 109 | TString out="HLT Log "; |
110 | out+=strSeverity; | |
111 | if (origin) {out+=": "; out+=origin;} | |
112 | out+=" "; out+=message; | |
113 | if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) { | |
114 | out+=" ("; out+=keyword; out +=")"; | |
115 | } | |
116 | cout << out.Data() << endl; | |
3495cce2 | 117 | return iResult; |
118 | } | |
119 | ||
120 | const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) { | |
121 | int tgtLen=0; | |
122 | int iBufferSize=LOG_BUFFER_SIZE; | |
5f1685a0 | 123 | char* tgtBuffer=gAliHLTLoggingBuffer; |
3495cce2 | 124 | tgtBuffer[tgtLen]=0; |
125 | ||
85465857 | 126 | #if (defined LOG_PREFIX) |
3495cce2 | 127 | tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix |
85465857 | 128 | #endif |
3495cce2 | 129 | if (tgtLen>=0) { |
130 | tgtBuffer+=tgtLen; iBufferSize-=tgtLen; | |
131 | tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap); | |
132 | if (tgtLen>0) { | |
133 | tgtBuffer+=tgtLen; | |
134 | // if (tgtLen<LOG_BUFFER_SIZE-1) { | |
135 | // *tgtBuffer++='\n'; // add newline if space in buffer | |
136 | // } | |
137 | *tgtBuffer=0; // terminate the buffer | |
138 | } | |
139 | } | |
5f1685a0 | 140 | return gAliHLTLoggingBuffer; |
3495cce2 | 141 | } |
142 | ||
8ede8717 | 143 | int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) { |
85465857 | 144 | int iResult=CheckFilter(severity); |
145 | if (iResult>0) { | |
146 | va_list args; | |
147 | va_start(args, format); | |
148 | if (fLoggingFunc) { | |
149 | iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); | |
150 | } else { | |
151 | iResult = Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); | |
152 | } | |
3495cce2 | 153 | } |
85465857 | 154 | return iResult; |
3495cce2 | 155 | } |
156 | ||
8ede8717 | 157 | int AliHLTLogging::LoggingVarargs( AliHLTComponentLogSeverity severity, const char* origin_class, const char* origin_func, ... ) const |
3495cce2 | 158 | { |
85465857 | 159 | int iResult=CheckFilter(severity); |
160 | if (iResult>0) { | |
161 | int iMaxSize=LOG_BUFFER_SIZE-1; | |
162 | int iPos=0; | |
163 | const char* separator=""; | |
5f1685a0 | 164 | gAliHLTLoggingOriginBuffer[iPos]=0; |
85465857 | 165 | if (origin_class) { |
166 | if ((int)strlen(origin_class)<iMaxSize-iPos) { | |
5f1685a0 | 167 | strcpy(&gAliHLTLoggingOriginBuffer[iPos], origin_class); |
85465857 | 168 | iPos+=strlen(origin_class); |
169 | separator="::"; | |
170 | } | |
3495cce2 | 171 | } |
85465857 | 172 | if (origin_func) { |
173 | if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) { | |
5f1685a0 | 174 | strcpy(&gAliHLTLoggingOriginBuffer[iPos], separator); |
85465857 | 175 | iPos+=strlen(separator); |
5f1685a0 | 176 | strcpy(&gAliHLTLoggingOriginBuffer[iPos], origin_func); |
85465857 | 177 | iPos+=strlen(origin_func); |
178 | } | |
3495cce2 | 179 | } |
85465857 | 180 | va_list args; |
181 | va_start(args, origin_func); | |
182 | const char* format = va_arg(args, const char*); | |
183 | ||
184 | const char* message=format; | |
8b250b0e | 185 | const char* qualifier=NULL; |
85465857 | 186 | if ((qualifier=strchr(format, '%'))!=NULL) { |
187 | message=AliHLTLogging::BuildLogString(format, args); | |
188 | } | |
189 | if (fLoggingFunc) { | |
5f1685a0 | 190 | iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, gAliHLTLoggingOriginBuffer, GetKeyword(), message); |
85465857 | 191 | } else { |
5f1685a0 | 192 | iResult=Message(NULL/*fParam*/, severity, gAliHLTLoggingOriginBuffer, GetKeyword(), message); |
85465857 | 193 | } |
194 | va_end(args); | |
3495cce2 | 195 | } |
3495cce2 | 196 | return iResult; |
197 | } | |
198 | ||
8ede8717 | 199 | int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const |
3495cce2 | 200 | { |
85465857 | 201 | int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0; |
3495cce2 | 202 | return iResult; |
203 | } |