]>
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> * | |
8 | * Artur Szostak <artursz@iafrica.com> * | |
9 | * for The ALICE Off-line Project. * | |
10 | * * | |
11 | * Permission to use, copy, modify and distribute this software and its * | |
12 | * documentation strictly for non-commercial purposes is hereby granted * | |
13 | * without fee, provided that the above copyright notice appears in all * | |
14 | * copies and that both the copyright notice and this permission notice * | |
15 | * appear in the supporting documentation. The authors make no claims * | |
16 | * about the suitability of this software for any purpose. It is * | |
17 | * provided "as is" without express or implied warranty. * | |
18 | **************************************************************************/ | |
19 | ||
20 | /////////////////////////////////////////////////////////////////////////////// | |
21 | // // | |
22 | // HLT logging tools // | |
23 | // // | |
24 | /////////////////////////////////////////////////////////////////////////////// | |
25 | ||
26 | #if __GNUC__== 3 | |
27 | using namespace std; | |
28 | #endif | |
29 | ||
a5854ddd | 30 | #include <cerrno> |
3495cce2 | 31 | #include "AliL3StandardIncludes.h" |
32 | #include "AliHLTLogging.h" | |
a5854ddd | 33 | #include <cstdarg> |
34 | #include <string> | |
3495cce2 | 35 | |
36 | ClassImp(AliHLTLogging) | |
37 | ||
38 | char AliHLTLogging::fLogBuffer[LOG_BUFFER_SIZE]=""; | |
39 | char AliHLTLogging::fOriginBuffer[LOG_BUFFER_SIZE]=""; | |
40 | ||
85465857 | 41 | AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll; |
5ec8e281 | 42 | AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL; |
3495cce2 | 43 | |
44 | AliHLTLogging::AliHLTLogging() | |
45 | { | |
85465857 | 46 | fpDefaultKeyword=NULL; |
47 | fpCurrentKeyword=NULL; | |
48 | //fLocalLogFilter=kHLTLogDefault; | |
49 | fLocalLogFilter=kHLTLogAll; | |
3495cce2 | 50 | } |
51 | ||
52 | ||
53 | AliHLTLogging::~AliHLTLogging() | |
54 | { | |
55 | } | |
56 | ||
bb16cc41 | 57 | int AliHLTLogging::Init(AliHLTfctLogging pFun) |
58 | { | |
59 | if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) { | |
60 | (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function"); | |
61 | } | |
62 | fLoggingFunc=pFun; | |
63 | return 0; | |
64 | } | |
65 | ||
3495cce2 | 66 | int AliHLTLogging::Message(void *param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message) { |
67 | int iResult=0; | |
68 | const char* strSeverity=""; | |
69 | switch (severity) { | |
70 | case kHLTLogBenchmark: | |
71 | strSeverity="benchmark"; | |
72 | break; | |
73 | case kHLTLogDebug: | |
74 | strSeverity="debug"; | |
75 | break; | |
76 | case kHLTLogInfo: | |
77 | strSeverity="info"; | |
78 | break; | |
79 | case kHLTLogWarning: | |
80 | strSeverity="warning"; | |
81 | break; | |
82 | case kHLTLogError: | |
83 | strSeverity="error"; | |
84 | break; | |
85 | case kHLTLogFatal: | |
86 | strSeverity="fatal"; | |
87 | break; | |
88 | default: | |
89 | break; | |
90 | } | |
85465857 | 91 | cout << "HLT Log " << strSeverity << ": " << origin << " " << message; |
92 | if (strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) | |
93 | cout << " (" << keyword << ")"; | |
94 | cout << endl; | |
3495cce2 | 95 | return iResult; |
96 | } | |
97 | ||
98 | const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) { | |
99 | int tgtLen=0; | |
100 | int iBufferSize=LOG_BUFFER_SIZE; | |
101 | char* tgtBuffer=fLogBuffer; | |
102 | tgtBuffer[tgtLen]=0; | |
103 | ||
85465857 | 104 | #if (defined LOG_PREFIX) |
3495cce2 | 105 | tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix |
85465857 | 106 | #endif |
3495cce2 | 107 | if (tgtLen>=0) { |
108 | tgtBuffer+=tgtLen; iBufferSize-=tgtLen; | |
109 | tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap); | |
110 | if (tgtLen>0) { | |
111 | tgtBuffer+=tgtLen; | |
112 | // if (tgtLen<LOG_BUFFER_SIZE-1) { | |
113 | // *tgtBuffer++='\n'; // add newline if space in buffer | |
114 | // } | |
115 | *tgtBuffer=0; // terminate the buffer | |
116 | } | |
117 | } | |
118 | return fLogBuffer; | |
119 | } | |
120 | ||
121 | int AliHLTLogging::Logging(AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) { | |
85465857 | 122 | int iResult=CheckFilter(severity); |
123 | if (iResult>0) { | |
124 | va_list args; | |
125 | va_start(args, format); | |
126 | if (fLoggingFunc) { | |
127 | iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); | |
128 | } else { | |
129 | iResult = Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); | |
130 | } | |
3495cce2 | 131 | } |
85465857 | 132 | return iResult; |
3495cce2 | 133 | } |
134 | ||
135 | int AliHLTLogging::LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func, ... ) | |
136 | { | |
85465857 | 137 | int iResult=CheckFilter(severity); |
138 | if (iResult>0) { | |
139 | int iMaxSize=LOG_BUFFER_SIZE-1; | |
140 | int iPos=0; | |
141 | const char* separator=""; | |
142 | fOriginBuffer[iPos]=0; | |
143 | if (origin_class) { | |
144 | if ((int)strlen(origin_class)<iMaxSize-iPos) { | |
145 | strcpy(&fOriginBuffer[iPos], origin_class); | |
146 | iPos+=strlen(origin_class); | |
147 | separator="::"; | |
148 | } | |
3495cce2 | 149 | } |
85465857 | 150 | if (origin_func) { |
151 | if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) { | |
152 | strcpy(&fOriginBuffer[iPos], separator); | |
153 | iPos+=strlen(separator); | |
154 | strcpy(&fOriginBuffer[iPos], origin_func); | |
155 | iPos+=strlen(origin_func); | |
156 | } | |
3495cce2 | 157 | } |
85465857 | 158 | va_list args; |
159 | va_start(args, origin_func); | |
160 | const char* format = va_arg(args, const char*); | |
161 | ||
162 | const char* message=format; | |
163 | char* qualifier=NULL; | |
164 | if ((qualifier=strchr(format, '%'))!=NULL) { | |
165 | message=AliHLTLogging::BuildLogString(format, args); | |
166 | } | |
167 | if (fLoggingFunc) { | |
168 | iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, fOriginBuffer, GetKeyword(), message); | |
169 | } else { | |
170 | iResult=Message(NULL/*fParam*/, severity, fOriginBuffer, GetKeyword(), message); | |
171 | } | |
172 | va_end(args); | |
3495cce2 | 173 | } |
3495cce2 | 174 | return iResult; |
175 | } | |
176 | ||
177 | int AliHLTLogging::CheckFilter(AliHLTComponent_LogSeverity severity) | |
178 | { | |
85465857 | 179 | int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0; |
3495cce2 | 180 | return iResult; |
181 | } |