3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
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 **************************************************************************/
19 /** @file AliHLTLogging.cxx
20 @author Matthias Richter, Timm Steinbeck
22 @brief Implementation of HLT logging primitives.
30 #include "AliL3StandardIncludes.h"
31 #include "AliHLTLogging.h"
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTLogging)
38 AliHLTLogging::AliHLTLogging()
40 fpDefaultKeyword=NULL;
41 fpCurrentKeyword=NULL;
42 //fLocalLogFilter=kHLTLogDefault;
43 fLocalLogFilter=kHLTLogAll;
46 char AliHLTLogging::fLogBuffer[LOG_BUFFER_SIZE]="";
47 char AliHLTLogging::fOriginBuffer[LOG_BUFFER_SIZE]="";
48 AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll;
49 AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL;
51 AliHLTLogging::~AliHLTLogging()
55 int AliHLTLogging::Init(AliHLTfctLogging pFun)
57 if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) {
58 (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
64 int AliHLTLogging::Message(void *param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message) {
66 const char* strSeverity="";
68 case kHLTLogBenchmark:
69 strSeverity="benchmark";
78 strSeverity="warning";
89 cout << "HLT Log " << strSeverity << ": " << origin << " " << message;
90 if (strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0)
91 cout << " (" << keyword << ")";
96 const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) {
98 int iBufferSize=LOG_BUFFER_SIZE;
99 char* tgtBuffer=fLogBuffer;
102 #if (defined LOG_PREFIX)
103 tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix
106 tgtBuffer+=tgtLen; iBufferSize-=tgtLen;
107 tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap);
110 // if (tgtLen<LOG_BUFFER_SIZE-1) {
111 // *tgtBuffer++='\n'; // add newline if space in buffer
113 *tgtBuffer=0; // terminate the buffer
119 int AliHLTLogging::Logging(AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) {
120 int iResult=CheckFilter(severity);
123 va_start(args, format);
125 iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
127 iResult = Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
133 int AliHLTLogging::LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func, ... )
135 int iResult=CheckFilter(severity);
137 int iMaxSize=LOG_BUFFER_SIZE-1;
139 const char* separator="";
140 fOriginBuffer[iPos]=0;
142 if ((int)strlen(origin_class)<iMaxSize-iPos) {
143 strcpy(&fOriginBuffer[iPos], origin_class);
144 iPos+=strlen(origin_class);
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);
157 va_start(args, origin_func);
158 const char* format = va_arg(args, const char*);
160 const char* message=format;
161 char* qualifier=NULL;
162 if ((qualifier=strchr(format, '%'))!=NULL) {
163 message=AliHLTLogging::BuildLogString(format, args);
166 iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, fOriginBuffer, GetKeyword(), message);
168 iResult=Message(NULL/*fParam*/, severity, fOriginBuffer, GetKeyword(), message);
175 int AliHLTLogging::CheckFilter(AliHLTComponent_LogSeverity severity)
177 int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;