3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT 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 AliHLTDynamicAliLog.cxx
20 @author Matthias Richter
22 @brief Implementation of dynamically loaded AliLog functionality
29 #include "AliHLTLogging.h"
30 #include "AliHLTDataTypes.h"
33 * Notification callback for AliRoot logging methods
35 void LogNotification(AliLog::EType_t /*level*/, const char* /*message*/)
37 // Notification callback for AliRoot logging methods
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);
43 AliHLTComponentLogSeverity level=kHLTLogNone;
45 TString logstring(AliHLTLogging::fgLogstr.str().c_str());
46 if (logstring.Length()<2) return;
47 switch (logstring[0]) {
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);
77 message=message.Strip(TString::kTrailing, '\n');
79 hltlog.Logging(level, origin.Data(), "AliLog", message.Data());
80 AliHLTLogging::fgLogstr.clear();
82 AliHLTLogging::fgLogstr.str(empty);
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
91 extern "C" int AliDynamicMessage(AliHLTComponentLogSeverity severity,
92 const char* originClass, const char* originFunc,
93 const char* file, int line, const char* message)
95 // see header file for class documentation
98 case kHLTLogBenchmark:
99 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
102 AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
105 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
108 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
111 AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
114 AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
116 case kHLTLogImportant:
117 AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
120 AliLog::Message(AliLog::kInfo, message, "HLT", originClass?originClass:"AliHLT", originFunc, file, line);
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.
132 extern "C" int InitAliDynamicMessageCallback()
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 #ifndef NO_ALILOG_GETROOTLOGGER
138 AliLog* log = AliLog::GetRootLogger();
140 AliLog* log = new AliLog;
141 #endif //NO_ALILOG_GETROOTLOGGER
142 log->SetLogNotification(LogNotification);
143 log->SetStreamOutput(&AliHLTLogging::fgLogstr);
144 log->SetPrintScope(true);
146 #endif // NO_ALILOG_NOTIFICATION