]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTLogging.cxx
adaption to new logging class, added functionality to AliHLTSystem to build a task...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTLogging.cxx
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
30 #include <errno.h>
31 //#include <string.h>
32 #include "AliL3StandardIncludes.h"
33 #include "AliHLTLogging.h"
34 #include <stdarg.h>
35 #include <string.h>
36
37 ClassImp(AliHLTLogging)
38
39 char AliHLTLogging::fLogBuffer[LOG_BUFFER_SIZE]="";
40 char AliHLTLogging::fOriginBuffer[LOG_BUFFER_SIZE]="";
41
42 AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=(AliHLTComponent_LogSeverity)0;
43 AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL;
44
45 AliHLTLogging::AliHLTLogging()
46 {
47 }
48
49
50 AliHLTLogging::~AliHLTLogging()
51 {
52 }
53
54 int AliHLTLogging::Message(void *param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message) {
55   int iResult=0;
56   const char* strSeverity="";
57   switch (severity) {
58   case kHLTLogBenchmark: 
59     strSeverity="benchmark";
60     break;
61   case kHLTLogDebug:
62     strSeverity="debug";
63     break;
64   case kHLTLogInfo:
65     strSeverity="info";
66     break;
67   case kHLTLogWarning:
68     strSeverity="warning";
69     break;
70   case kHLTLogError:
71     strSeverity="error";
72     break;
73   case kHLTLogFatal:
74     strSeverity="fatal";
75     break;
76   default:
77     break;
78   }
79   cout << "HLT Log " << strSeverity << ": " << origin << " (" << keyword << ") " << message << endl;
80   return iResult;
81 }
82
83 const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) {
84   int tgtLen=0;
85   int iBufferSize=LOG_BUFFER_SIZE;
86   char* tgtBuffer=fLogBuffer;
87   tgtBuffer[tgtLen]=0;
88
89   tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix
90   if (tgtLen>=0) {
91     tgtBuffer+=tgtLen; iBufferSize-=tgtLen;
92     tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap);
93     if (tgtLen>0) {
94       tgtBuffer+=tgtLen;
95 //       if (tgtLen<LOG_BUFFER_SIZE-1) {
96 //      *tgtBuffer++='\n'; // add newline if space in buffer
97 //      }
98       *tgtBuffer=0; // terminate the buffer
99     }
100   }
101   return fLogBuffer;
102 }
103
104 int AliHLTLogging::Logging(AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) {
105   va_list args;
106   va_start(args, format);
107   if (fLoggingFunc) {
108     return (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
109   } else {
110     return Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
111   }
112   return -ENOSYS;
113 }
114
115 int AliHLTLogging::LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func,  ... )
116 {
117   int iResult=0;
118   int iMaxSize=LOG_BUFFER_SIZE-1;
119   int iPos=0;
120   const char* separator="";
121   fOriginBuffer[iPos]=0;
122   if (origin_class) {
123     if ((int)strlen(origin_class)<iMaxSize-iPos) {
124       strcpy(&fOriginBuffer[iPos], origin_class);
125       iPos+=strlen(origin_class);
126       separator="::";
127     }
128   }
129   if (origin_func) {
130     if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) {
131       strcpy(&fOriginBuffer[iPos], separator);
132       iPos+=strlen(separator);
133       strcpy(&fOriginBuffer[iPos], origin_func);
134       iPos+=strlen(origin_func);
135     }
136   }
137   va_list args;
138   va_start(args, origin_func);
139   const char* format = va_arg(args, const char*);
140
141   const char* message=format;
142   char* qualifier=NULL;
143   const char* keyword="no key";
144   if ((qualifier=strchr(format, '%'))!=NULL) {
145     message=AliHLTLogging::BuildLogString(format, args);
146   }
147   if (fLoggingFunc) {
148     iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, fOriginBuffer, keyword, message);
149   } else {
150     iResult=Message(NULL/*fParam*/, severity, fOriginBuffer, keyword, message);
151   }
152   va_end(args);
153   return iResult;
154 }
155
156 int AliHLTLogging::CheckFilter(AliHLTComponent_LogSeverity severity)
157 {
158   int iResult=1;
159   return iResult;
160 }