]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTDynamicAliLog.cxx
Renaming AliHLTReconstructorBase to AliHLTPluginBase to reflect the
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTDynamicAliLog.cxx
CommitLineData
d0dd2b78 1// @(#) $Id$
2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT 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
19/** @file AliHLTDynamicAliLog.cxx
20 @author Matthias Richter
21 @date
22 @brief Implementation of dynamically loaded AliLog functionality
23*/
24
25#include <sstream>
26#include <iostream>
b2065764 27#include "TString.h"
d0dd2b78 28#include "AliLog.h"
29#include "AliHLTLogging.h"
30#include "AliHLTDataTypes.h"
31
32/**
33 * Notification callback for AliRoot logging methods
34 */
35void LogNotification(AliLog::EType_t /*level*/, const char* /*message*/)
36{
37 // Notification callback for AliRoot logging methods
38
39 AliHLTLogging hltlog;
40 // in case of the initialized callback we never want to redirect
41 // HLT logging messages to AliLog (that would be a circular function call)
42 hltlog.SwitchAliLog(0);
b2065764 43 AliHLTComponentLogSeverity level=kHLTLogNone;
44 int offset=2;
45 TString logstring(AliHLTLogging::fgLogstr.str().c_str());
46 if (logstring.Length()<2) return;
47 switch (logstring[0]) {
48 case 'D':
49 level=kHLTLogDebug;
50 break;
51 case 'I':
52 level=kHLTLogInfo;
53 break;
54 case 'W':
55 level=kHLTLogWarning;
56 break;
57 case 'E':
58 level=kHLTLogError;
59 break;
60 case 'F':
61 level=kHLTLogFatal;
62 break;
63 default:
64 level=kHLTLogInfo;
65 offset=0;
66 }
67
68 TString origin=&logstring[offset];
69 TString message=origin;
70 int blank=origin.First(' ');
71 if (blank>0 && origin[blank-1]==':') {
72 origin.Remove(blank-1, origin.Length());
73 message.Remove(0, blank+1);
74 } else {
75 origin="";
76 }
77 message=message.Strip(TString::kTrailing, '\n');
78
79 hltlog.Logging(level, origin.Data(), "AliLog", message.Data());
d0dd2b78 80 AliHLTLogging::fgLogstr.clear();
81 string empty("");
82 AliHLTLogging::fgLogstr.str(empty);
83}
84
85/**
86 * This is the entry point for AliLog messages.
87 * The function pointer is fetched by the AliLogging class after libAliHLTUtil
88 * was loaded dynamically. By that we can keep libHLTbase free of AliRoot
89 * libraries.
90 */
91extern "C" int AliDynamicMessage(AliHLTComponentLogSeverity severity,
92 const char* originClass, const char* originFunc,
93 const char* file, int line, const char* message)
94{
95 // see header file for class documentation
96
97 switch (severity) {
98 case kHLTLogBenchmark:
99 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
100 break;
101 case kHLTLogDebug:
102 AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
103 break;
104 case kHLTLogInfo:
105 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
106 break;
107 case kHLTLogWarning:
108 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
109 break;
110 case kHLTLogError:
111 AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
112 break;
113 case kHLTLogFatal:
114 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
115 break;
b2065764 116 case kHLTLogImportant:
117 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
118 break;
d0dd2b78 119 default:
120 break;
121 }
122 return 0;
123}
124
125/**
126 * Init the AliLog callback.
127 * If libHLTbase is used within AliRoot, no message callback is initialized since
128 * all logging happens through AliRoot. If externally used by other frameworks (e.g.
129 * PubSub), all messages from components to AliLog must be trapped and redirected
130 * to the external callback.
131 */
132extern "C" int InitAliDynamicMessageCallback()
133{
134 // older versions of AliLog does not support the notification callback and
135 // stringstreams, but they support the logging macros in general
136#ifndef NO_ALILOG_NOTIFICATION
137 AliLog* log=new AliLog;
138 log->SetLogNotification(LogNotification);
139 log->SetStreamOutput(&AliHLTLogging::fgLogstr);
b2065764 140 log->SetPrintScope(true);
d0dd2b78 141 return 0;
142#endif // NO_ALILOG_NOTIFICATION
143 return -ENOSYS;
144}