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