diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-06-26 18:54:17 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-06-26 18:54:17 +0100 |
commit | ef4dfef7259c94f9ee2359851c24c9d4cd0d2c3f (patch) | |
tree | af34e3c0a522d09c2e1a9351f7c770a1970e0ce6 | |
parent | Dedupe updating logger writers (diff) | |
download | icetray-ef4dfef7259c94f9ee2359851c24c9d4cd0d2c3f.tar.bz2 icetray-ef4dfef7259c94f9ee2359851c24c9d4cd0d2c3f.tar.xz icetray-ef4dfef7259c94f9ee2359851c24c9d4cd0d2c3f.zip |
Use AdHoc's GlobalStatic for the default log manager, not an instance in the service
-rw-r--r-- | icetray/icetray/icetrayService.cpp | 14 | ||||
-rw-r--r-- | icetray/icetray/icetrayService.h | 4 | ||||
-rw-r--r-- | icetray/icetray/logger.cpp | 9 | ||||
-rw-r--r-- | icetray/icetray/logger.h | 7 | ||||
-rw-r--r-- | 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<Logging::LogWriterFactory>()) { 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<Logging::LogWriterPrx> logWriters; }; typedef IceInternal::Handle<Service> 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 <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/classification.hpp> #include <slicer/modelPartsTypes.h> +#include <globalStatic.impl.h> 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 <buffer.h> #include <boost/thread/shared_mutex.hpp> #include <Ice/Properties.h> +#include <globalStatic.h> 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(); } |