From ef4dfef7259c94f9ee2359851c24c9d4cd0d2c3f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Jun 2017 18:54:17 +0100 Subject: Use AdHoc's GlobalStatic for the default log manager, not an instance in the service --- icetray/icetray/icetrayService.cpp | 14 ++++++++------ icetray/icetray/icetrayService.h | 4 +--- icetray/icetray/logger.cpp | 9 +++++++++ icetray/icetray/logger.h | 7 ++++++- icetray/unittests/testIceTrayLogger.cpp | 1 + 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/icetray/icetray/icetrayService.cpp b/icetray/icetray/icetrayService.cpp index f04a200..4b403d1 100644 --- a/icetray/icetray/icetrayService.cpp +++ b/icetray/icetray/icetrayService.cpp @@ -29,10 +29,13 @@ namespace IceTray { void Service::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) { adp = ic->createObjectAdapter(name); + auto logManager = LOGMANAGER(); for (auto logWriterFactory : AdHoc::PluginManager::getDefault()->getAll()) { auto logWriter = logWriterFactory->implementation()->create(ic->getProperties().get()); if (logWriter->lowestLevel()) { - logManager.addWriter(Logging::LogWriterPrx::uncheckedCast(adp->addWithUUID(logWriter))); + auto prx = Logging::LogWriterPrx::uncheckedCast(adp->addWithUUID(logWriter)); + logWriters.insert(prx); + logManager->addWriter(prx); } } addObjects(name, ic, args, adp); @@ -41,6 +44,10 @@ namespace IceTray { void Service::stop() { + auto logManager = LOGMANAGER(); + for (auto prx : logWriters) { + logManager->removeWriter(prx); + } adp->deactivate(); adp->destroy(); } @@ -52,11 +59,6 @@ namespace IceTray { p->getPropertyWithDefault("DryIce.PoolProvider", "DefaultPool"), name, type, p)); } - - Logging::LogManager * Service::getLogManager() - { - return &logManager; - } } extern "C" { diff --git a/icetray/icetray/icetrayService.h b/icetray/icetray/icetrayService.h index ffc4251..d754bf9 100644 --- a/icetray/icetray/icetrayService.h +++ b/icetray/icetray/icetrayService.h @@ -21,15 +21,13 @@ namespace IceTray { DatabasePoolPtr getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & prefix); - Logging::LogManager * getLogManager(); - static Service * getCurrent(); private: friend class DryIce; Ice::ObjectAdapterPtr adp; - Logging::LogManager logManager; static Service * current; + std::set logWriters; }; typedef IceInternal::Handle ServicePtr; diff --git a/icetray/icetray/logger.cpp b/icetray/icetray/logger.cpp index fadb0a4..e36e193 100644 --- a/icetray/icetray/logger.cpp +++ b/icetray/icetray/logger.cpp @@ -6,9 +6,12 @@ #include #include #include +#include INSTANTIATEFACTORY(IceTray::Logging::LogWriter, Ice::Properties *); +template class ::AdHoc::GlobalStatic<::IceTray::Logging::LogManager>; + namespace IceTray { namespace Logging { LoggerBase::LoggerBase(const std::string & domain) : @@ -154,6 +157,12 @@ namespace IceTray { updateLoggerWriters(); } + LogManager * + LogManager::getDefault() + { + return ::AdHoc::GlobalStatic<::IceTray::Logging::LogManager>::get(); + } + AbstractLogWriter::AbstractLogWriter() { } diff --git a/icetray/icetray/logger.h b/icetray/icetray/logger.h index 75925b9..81d650c 100644 --- a/icetray/icetray/logger.h +++ b/icetray/icetray/logger.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace IceTray { namespace Logging { @@ -81,6 +82,8 @@ namespace IceTray { void addWriter(LogWriterPrx writer); void removeWriter(LogWriterPrx writer); + static LogManager * getDefault(); + private: void updateLoggerWriters() const; mutable boost::shared_mutex _lock; @@ -109,7 +112,9 @@ namespace IceTray { } } -#define LOGMANAGER() (::IceTray::Service::getCurrent()->getLogManager()) +namespace LOG = ::IceTray::Logging; + +#define LOGMANAGER() (::IceTray::Logging::LogManager::getDefault()) #endif diff --git a/icetray/unittests/testIceTrayLogger.cpp b/icetray/unittests/testIceTrayLogger.cpp index b7c3c49..352255b 100644 --- a/icetray/unittests/testIceTrayLogger.cpp +++ b/icetray/unittests/testIceTrayLogger.cpp @@ -278,6 +278,7 @@ BOOST_AUTO_TEST_CASE( getLogger ) auto logger = LOGMANAGER()->getLogger("test.domain"); BOOST_REQUIRE(logger); BOOST_REQUIRE_EQUAL("test.domain", logger->getDomain()); + this->stop(); ic->destroy(); } -- cgit v1.2.3