]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/rec/AliHLTDynamicAliLog.cxx
Keep only the forward mapping array persistent, the inverse one is created on demand...
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTDynamicAliLog.cxx
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 "AliLog.h"
28 #include "AliHLTLogging.h"
29 #include "AliHLTDataTypes.h"
30
31 /**
32  * Notification callback for AliRoot logging methods
33  */
34 void LogNotification(AliLog::EType_t /*level*/, const char* /*message*/)
35 {
36   // Notification callback for AliRoot logging methods
37
38   AliHLTLogging hltlog;
39   // in case of the initialized callback we never want to redirect
40   // HLT logging messages to AliLog (that would be a circular function call)
41   hltlog.SwitchAliLog(0);
42   hltlog.Logging(kHLTLogInfo, "NotificationHandler", "AliLog", AliHLTLogging::fgLogstr.str().c_str());
43   AliHLTLogging::fgLogstr.clear();
44   string empty("");
45   AliHLTLogging::fgLogstr.str(empty);
46 }
47
48 /**
49  * This is the entry point for AliLog messages.
50  * The function pointer is fetched by the AliLogging class after libAliHLTUtil
51  * was loaded dynamically. By that we can keep libHLTbase free of AliRoot
52  * libraries.
53  */
54 extern "C" int AliDynamicMessage(AliHLTComponentLogSeverity severity, 
55                                  const char* originClass, const char* originFunc,
56                                  const char* file, int line, const char* message) 
57 {
58   // see header file for class documentation
59
60   switch (severity) {
61   case kHLTLogBenchmark: 
62     AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
63     break;
64   case kHLTLogDebug:
65     AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line);
66     break;
67   case kHLTLogInfo:
68     AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line);
69     break;
70   case kHLTLogWarning:
71     AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
72     break;
73   case kHLTLogError:
74     AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line);
75     break;
76   case kHLTLogFatal:
77     AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line);
78     break;
79   default:
80     break;
81   }
82   return 0;
83 }
84
85 /**
86  * Init the AliLog callback.
87  * If libHLTbase is used within AliRoot, no message callback is initialized since
88  * all logging happens through AliRoot. If externally used by other frameworks (e.g.
89  * PubSub), all messages from components to AliLog must be trapped and redirected
90  * to the external callback.
91  */
92 extern "C" int InitAliDynamicMessageCallback() 
93 {
94   // older versions of AliLog does not support the notification callback and
95   // stringstreams, but they support the logging macros in general
96 #ifndef NO_ALILOG_NOTIFICATION
97   AliLog* log=new AliLog;
98   log->SetLogNotification(LogNotification);
99   log->SetStreamOutput(&AliHLTLogging::fgLogstr);
100   return 0;
101 #endif // NO_ALILOG_NOTIFICATION
102   return -ENOSYS;
103 }