Line data Source code
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>
27 : #include "TString.h"
28 : #include "AliLog.h"
29 : #include "AliHLTLogging.h"
30 : #include "AliHLTDataTypes.h"
31 :
32 : /**
33 : * Notification callback for AliRoot logging methods
34 : */
35 : void LogNotification(AliLog::EType_t /*level*/, const char* /*message*/)
36 : {
37 : // Notification callback for AliRoot logging methods
38 :
39 0 : 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 0 : hltlog.SwitchAliLog(0);
43 : AliHLTComponentLogSeverity level=kHLTLogNone;
44 : int offset=2;
45 0 : TString logstring(AliHLTLogging::fgLogstr.str().c_str());
46 0 : if (logstring.Length()<2) return;
47 0 : switch (logstring[0]) {
48 : case 'D':
49 : level=kHLTLogDebug;
50 0 : break;
51 : case 'I':
52 : level=kHLTLogInfo;
53 0 : break;
54 : case 'W':
55 : level=kHLTLogWarning;
56 0 : break;
57 : case 'E':
58 : level=kHLTLogError;
59 0 : break;
60 : case 'F':
61 : level=kHLTLogFatal;
62 0 : break;
63 : default:
64 : level=kHLTLogInfo;
65 : offset=0;
66 0 : }
67 :
68 0 : TString origin=&logstring[offset];
69 0 : TString message=origin;
70 0 : int blank=origin.First(' ');
71 0 : if (blank>0 && origin[blank-1]==':') {
72 0 : origin.Remove(blank-1, origin.Length());
73 0 : message.Remove(0, blank+1);
74 : } else {
75 0 : origin="";
76 : }
77 0 : message=message.Strip(TString::kTrailing, '\n');
78 :
79 0 : hltlog.Logging(level, origin.Data(), "AliLog", message.Data());
80 0 : AliHLTLogging::fgLogstr.clear();
81 0 : string empty("");
82 0 : AliHLTLogging::fgLogstr.str(empty);
83 0 : }
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 : */
91 : extern "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 84 : switch (severity) {
98 : case kHLTLogBenchmark:
99 0 : AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
100 0 : break;
101 : case kHLTLogDebug:
102 0 : AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
103 0 : break;
104 : case kHLTLogInfo:
105 0 : AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
106 0 : break;
107 : case kHLTLogWarning:
108 0 : AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
109 0 : break;
110 : case kHLTLogError:
111 6 : AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
112 6 : break;
113 : case kHLTLogFatal:
114 0 : AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
115 0 : break;
116 : case kHLTLogImportant:
117 36 : AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
118 36 : break;
119 : default:
120 0 : AliLog::Message(AliLog::kInfo, message, "HLT", originClass?originClass:"AliHLT", originFunc, file, line);
121 0 : }
122 42 : 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 : */
132 : extern "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 : #ifndef NO_ALILOG_GETROOTLOGGER
138 0 : AliLog* log = AliLog::GetRootLogger();
139 : #else
140 : AliLog* log = new AliLog;
141 : #endif //NO_ALILOG_GETROOTLOGGER
142 0 : log->SetLogNotification(LogNotification);
143 0 : log->SetStreamOutput(&AliHLTLogging::fgLogstr);
144 0 : log->SetPrintScope(true);
145 0 : return 0;
146 : #endif // NO_ALILOG_NOTIFICATION
147 : return -ENOSYS;
148 : }
|