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