diff --git a/LCS/MessageBus/include/MessageBus/MsgBus.h b/LCS/MessageBus/include/MessageBus/MsgBus.h index 512e59287f6646fd838c373b49455324751c3a4c..f170c65c13a06b4a23c26a7a0125d17a943aecd4 100644 --- a/LCS/MessageBus/include/MessageBus/MsgBus.h +++ b/LCS/MessageBus/include/MessageBus/MsgBus.h @@ -40,6 +40,11 @@ namespace LOFAR { EXCEPTION_CLASS(MessageBusException, LOFAR::Exception); +namespace MessageBus { + // Generic initialisation of the Messaging framework + void init(); +} + class FromBus { public: @@ -75,7 +80,6 @@ private: qpid::messaging::Connection itsConnection; qpid::messaging::Session itsSession; qpid::messaging::Sender itsSender; - }; } // namespace LOFAR diff --git a/LCS/MessageBus/src/CMakeLists.txt b/LCS/MessageBus/src/CMakeLists.txt index a94c869d4f786f13bb99a6c7d80bbbe32156e2f8..db7c454bcb05eec8ee640c86b7380e332a5d5797 100644 --- a/LCS/MessageBus/src/CMakeLists.txt +++ b/LCS/MessageBus/src/CMakeLists.txt @@ -6,6 +6,7 @@ include(PythonInstall) set(messagebus_LIB_SRCS Package__Version.cc + LogSink.cc MsgBus.cc Message.cc) diff --git a/LCS/MessageBus/src/LogSink.cc b/LCS/MessageBus/src/LogSink.cc new file mode 100644 index 0000000000000000000000000000000000000000..9e698119ebd12d8dd313617a98ef5067d92c2c80 --- /dev/null +++ b/LCS/MessageBus/src/LogSink.cc @@ -0,0 +1,90 @@ +#include "lofar_config.h" + +#include "LogSink.h" +#include <Common/LofarLogger.h> + +#include <Common/SystemUtil.h> +#include <Common/StringUtil.h> +#include <string> +#include <sstream> + +#ifdef HAVE_QPID +#include <qpid/messaging/Logger.h> + +using namespace qpid::messaging; + +namespace LOFAR { + + class QpidLogSink: public LoggerOutput { + public: + QpidLogSink() { + } + + virtual void log(Level level, bool user, const char* file, int line, const char* function, const std::string& message) { + (void)user; + + // shorten filename to reduce spam + std::string filename = basename(file); + + // remove trailing \n from message (and other white space while we're at it) + std::string trimmed_message = message; + rtrim(trimmed_message, " \t\n"); + + // construct log message + std::stringstream msg; + msg << function << "(): " << trimmed_message << " (" << filename << ":" << line << ")"; + + // emit at the right level + switch(level) { + case trace: + case debug: + LOG_DEBUG(msg.str()); + break; + + case info: + case notice: + LOG_INFO(msg.str()); + break; + + case warning: + LOG_WARN(msg.str()); + break; + + case error: + LOG_ERROR(msg.str()); + break; + + case critical: + LOG_FATAL(msg.str()); + break; + } + } + }; + + static QpidLogSink qpidLogSink; + + void qpidlogsink_init() { + const char *argv[] = { + // Name of program (dummy) + "a.out", + + // QPID logger configuration parameters (see Logger::configure) + + // Disable all default QPID sinks + "--log-to-stdout", "off", + "--log-to-stderr", "off", + + // Trim the log messages + "--log-time", "off" + }; + int argc = sizeof argv / sizeof argv[0]; + + Logger::configure(argc, argv); + + // Add the LOFAR logger as a sink for QPID + Logger::setOutput(qpidLogSink); + } + +} // namespace LOFAR + +#endif diff --git a/LCS/MessageBus/src/LogSink.h b/LCS/MessageBus/src/LogSink.h new file mode 100644 index 0000000000000000000000000000000000000000..ddddee4c8dcb620abdcf2ef4506b87888ed9e50f --- /dev/null +++ b/LCS/MessageBus/src/LogSink.h @@ -0,0 +1,37 @@ +//# LogSink.h: Wrapper to initialise the QPID library +//# +//# Copyright (C) 2015 +//# ASTRON (Netherlands Institute for Radio Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +//# +//# This file is part of the LOFAR software suite. +//# The LOFAR software suite is free software: you can redistribute it and/or +//# modify it under the terms of the GNU General Public License as published +//# by the Free Software Foundation, either version 3 of the License, or +//# (at your option) any later version. +//# +//# The LOFAR software suite is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License along +//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. +//# +//# $Id$ + +#ifndef LOFAR_MESSAGEBUS_LOGSINK_H +#define LOFAR_MESSAGEBUS_LOGSINK_H + +namespace LOFAR { + +#ifdef HAVE_QPID + +void qpidlogsink_init(); + +#endif + +} // namespace LOFAR + +#endif + diff --git a/LCS/MessageBus/src/MsgBus.cc b/LCS/MessageBus/src/MsgBus.cc index 48abe5ccea4cd20c1ee53338dfbd09e246eee00d..828f485412115c00a045ce8274c63b2d15d99279 100644 --- a/LCS/MessageBus/src/MsgBus.cc +++ b/LCS/MessageBus/src/MsgBus.cc @@ -1,6 +1,7 @@ #include "lofar_config.h" #include <MessageBus/MsgBus.h> +#include "LogSink.h" #include <Common/LofarLogger.h> #ifdef HAVE_QPID @@ -20,6 +21,12 @@ namespace LOFAR { return Duration::FOREVER; } + namespace MessageBus { + void init() { + qpidlogsink_init(); + } + } + FromBus::FromBus(const std::string &address, const std::string &options, const std::string &broker) try: itsConnection(broker,"{reconnect:true}"), diff --git a/LCS/MessageBus/test/tMsgBus.cc b/LCS/MessageBus/test/tMsgBus.cc index 161630ff8b093ba41795467b0eea661fc8d96867..50096068e3825092d999afaab240b1819ab8c937 100644 --- a/LCS/MessageBus/test/tMsgBus.cc +++ b/LCS/MessageBus/test/tMsgBus.cc @@ -65,6 +65,10 @@ void compareMessages(qpid::messaging::Message& lhm, qpid::messaging::Message& rh int main(int argc, char* argv[]) { + INIT_LOGGER("tMsgBus"); + + MessageBus::init(); + std::string queue(argc == 2 ? argv[1] : "tMsgBus-test-queue"); cout << "Using queue " << queue << " (Syntax: " << argv[0] << " messagebus)" << endl; @@ -107,6 +111,7 @@ int main(int argc, char* argv[]) { showMessage(receivedMsg.qpidMsg()); cout << "--- All test successful! ---" << endl; + return (0); } diff --git a/MAC/APL/CEPCU/src/OnlineControl/OnlineControlMain.cc b/MAC/APL/CEPCU/src/OnlineControl/OnlineControlMain.cc index 1a0dadbfb119ca7d17b1862b81eb7be052a8122b..7089d0c5a4a4cb39c6677dd04edff624d3c485c9 100644 --- a/MAC/APL/CEPCU/src/OnlineControl/OnlineControlMain.cc +++ b/MAC/APL/CEPCU/src/OnlineControl/OnlineControlMain.cc @@ -23,6 +23,7 @@ #include <lofar_config.h> #include <Common/LofarLogger.h> #include <Common/Exception.h> +#include <MessageBus/MsgBus.h> #include "OnlineControl.h" @@ -44,6 +45,8 @@ int main(int argc, char* argv[]) GCFScheduler::instance()->init(argc, argv, argv[1]); + MessageBus::init(); + ParentControl* pc = ParentControl::instance(); pc->start(); // make initial transition diff --git a/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc b/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc index aa1bb8ebd60d8e5072fea2afccc35dcfbb2637e9..8b85c5da69b966a8cc99359af7a65b4c8e9e31af 100644 --- a/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc +++ b/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc @@ -28,6 +28,7 @@ #include <Common/ParameterSet.h> #include <GCF/TM/GCF_Protocols.h> #include <MACIO/MACServiceInfo.h> +#include <MessageBus/MsgBus.h> #include <MessageBus/Protocols/TaskSpecificationSystem.h> #include <GCF/PVSS/GCF_PVTypes.h> #include <APL/APLCommon/APL_Defines.h> diff --git a/MAC/APL/MainCU/src/MACScheduler/MACSchedulerMain.cc b/MAC/APL/MainCU/src/MACScheduler/MACSchedulerMain.cc index 5f6b5ab611740cd6d905fcf605ffe06a88305c9b..acb9afe7bc6a7fa07a2f409dc18959d95285811d 100644 --- a/MAC/APL/MainCU/src/MACScheduler/MACSchedulerMain.cc +++ b/MAC/APL/MainCU/src/MACScheduler/MACSchedulerMain.cc @@ -23,6 +23,7 @@ #include <lofar_config.h> #include <Common/LofarLogger.h> #include <Common/Exception.h> +#include <MessageBus/MsgBus.h> #include "MACScheduler.h" @@ -38,6 +39,8 @@ int main(int argc, char* argv[]) { GCFScheduler::instance()->init(argc, argv, "MACScheduler"); + MessageBus::init(); + ChildControl* cc = ChildControl::instance(); cc->start(); // make initial transition diff --git a/RTCP/Cobalt/GPUProc/src/rtcp.cc b/RTCP/Cobalt/GPUProc/src/rtcp.cc index 4bf0342c6a2460b48a5e3ad5115db943ee105e60..544e829e0d20c256ba92abe6e8a6a3960c429641 100644 --- a/RTCP/Cobalt/GPUProc/src/rtcp.cc +++ b/RTCP/Cobalt/GPUProc/src/rtcp.cc @@ -170,6 +170,10 @@ int main(int argc, char **argv) LOG_INFO("===== INIT ====="); + // Initialise message bus + LOG_INFO("----- Initialising MessageBus"); + MessageBus::init(); + // Create a parameters set object based on the inputs LOG_INFO("----- Reading Parset"); Parset ps(argv[optind]); diff --git a/RTCP/Cobalt/GPUProc/src/send_status.cc b/RTCP/Cobalt/GPUProc/src/send_status.cc index 51e4d69cfd0d2ed2f91ebbc6841ed16bbd1f6dd7..928be9e3bdb781a442ecf4da6884610be0ad28f9 100644 --- a/RTCP/Cobalt/GPUProc/src/send_status.cc +++ b/RTCP/Cobalt/GPUProc/src/send_status.cc @@ -20,6 +20,7 @@ #include <lofar_config.h> +#include <Common/LofarLogger.h> #include <CoInterface/Parset.h> #include <MessageBus/MsgBus.h> #include <MessageBus/Protocols/TaskFeedbackStatus.h> @@ -66,6 +67,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + INIT_LOGGER("send_status"); + MessageBus::init(); + Parset parset(argv[optind]); int success = atoi(argv[optind+1]); diff --git a/RTCP/Cobalt/OutputProc/src/outputProc.cc b/RTCP/Cobalt/OutputProc/src/outputProc.cc index 39407435760cceb38492b31110eba99d723617b0..4e469d7fdae0533efa95bb419898ee1e30ae63da 100644 --- a/RTCP/Cobalt/OutputProc/src/outputProc.cc +++ b/RTCP/Cobalt/OutputProc/src/outputProc.cc @@ -38,6 +38,7 @@ #include <CoInterface/Stream.h> #include <CoInterface/OMPThread.h> #include <OutputProc/Package__Version.h> +#include <MessageBus/MsgBus.h> #include "GPUProcIO.h" #include "IOPriority.h" @@ -97,6 +98,8 @@ int main(int argc, char *argv[]) INIT_LOGGER("outputProc"); // also attaches to CasaLogSink + MessageBus::init(); + LOG_DEBUG_STR("Started: " << argv[0] << ' ' << argv[1] << ' ' << argv[2]); LOG_INFO_STR("OutputProc version " << OutputProcVersion::getVersion() << " r" << OutputProcVersion::getRevision());