From 0b0d883a00751c946fab4c897bab01859c598a88 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 16 Jun 2009 14:07:06 +0200 Subject: Logger werden jetzt durch shared_ptr gespeichert --- src/Core/LogManager.cpp | 12 ++++++------ src/Core/LogManager.h | 16 ++++++++-------- src/mad.cpp | 2 +- src/modules/FileLogger/FileLogger.cpp | 6 +++--- src/modules/FileLogger/FileLogger.h | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp index bf9767b..91149f9 100644 --- a/src/Core/LogManager.cpp +++ b/src/Core/LogManager.cpp @@ -56,7 +56,7 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { if(entry[0].getKey().matches("Logger")) { if(entry[0][0].matches("Console")) { if(entry[1].empty()) { - registerLogger(static_cast(&consoleLogger)); + registerLogger(boost::static_pointer_cast(consoleLogger)); return true; } } @@ -71,10 +71,10 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { void LogManager::configFinished() { if(loggers.empty()) - registerLogger(static_cast(&consoleLogger)); + registerLogger(boost::static_pointer_cast(consoleLogger)); // TODO Debug - consoleLogger.Logger::setLevel(LoggerBase::DEBUG); + consoleLogger->Logger::setLevel(LoggerBase::DEBUG); queueLock.lock(); configured = true; @@ -84,7 +84,7 @@ void LogManager::configFinished() { void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) { if(level == LoggerBase::CRITICAL) - consoleLogger.logMessageDirect(category, level, timestamp, message); + consoleLogger->logMessageDirect(category, level, timestamp, message); queueLock.lock(); Message m = {category, level, timestamp, message}; @@ -116,7 +116,7 @@ void LogManager::loggerThread() { lock.unlock(); loggerLock.lock(); - for(std::set::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { + for(std::set >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) (*logger)->logMessage(message.category, message.level, message.timestamp, message.message); } @@ -131,7 +131,7 @@ void LogManager::loggerThread() { lock.unlock(); remoteLoggerLock.lock(); - for(std::set::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) { + for(std::set >::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) { if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) (*logger)->logMessage(message.category, message.level, message.timestamp, message.message, message.source); } diff --git a/src/Core/LogManager.h b/src/Core/LogManager.h index 6d75b82..8c8d091 100644 --- a/src/Core/LogManager.h +++ b/src/Core/LogManager.h @@ -78,10 +78,10 @@ class LogManager : public Configurable { static LogManager logManager; - ConsoleLogger consoleLogger; + boost::shared_ptr consoleLogger; - std::set loggers; - std::set remoteLoggers; + std::set > loggers; + std::set > remoteLoggers; bool configured, running; boost::mutex queueLock; @@ -101,7 +101,7 @@ class LogManager : public Configurable { queueCond.notify_one(); } - LogManager() : configured(false), running(false) {} + LogManager() : consoleLogger(new ConsoleLogger), configured(false), running(false) {} protected: virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled); @@ -111,25 +111,25 @@ class LogManager : public Configurable { void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message); void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source); - void registerLogger(Logger *logger) { + void registerLogger(boost::shared_ptr logger) { loggerLock.lock(); loggers.insert(logger); loggerLock.unlock(); } - void unregisterLogger(Logger *logger) { + void unregisterLogger(boost::shared_ptr logger) { loggerLock.lock(); loggers.erase(logger); loggerLock.unlock(); } - void registerLogger(RemoteLogger *logger) { + void registerLogger(boost::shared_ptr logger) { remoteLoggerLock.lock(); remoteLoggers.insert(logger); remoteLoggerLock.unlock(); } - void unregisterLogger(RemoteLogger *logger) { + void unregisterLogger(boost::shared_ptr logger) { remoteLoggerLock.lock(); remoteLoggers.erase(logger); remoteLoggerLock.unlock(); diff --git a/src/mad.cpp b/src/mad.cpp index 107f240..b1dbb8f 100644 --- a/src/mad.cpp +++ b/src/mad.cpp @@ -57,7 +57,7 @@ int main() { Common::RequestManager::get()->registerConnection(connection); - Core::Logger *networkLogger = new Daemon::Backends::NetworkLogger(connection); + boost::shared_ptr networkLogger(new Daemon::Backends::NetworkLogger(connection)); Core::LogManager::get()->registerLogger(networkLogger); diff --git a/src/modules/FileLogger/FileLogger.cpp b/src/modules/FileLogger/FileLogger.cpp index a78ab36..bdae536 100644 --- a/src/modules/FileLogger/FileLogger.cpp +++ b/src/modules/FileLogger/FileLogger.cpp @@ -26,7 +26,7 @@ namespace Mad { namespace Modules { FileLogger::ConfigHelper FileLogger::configHelper; -std::set FileLogger::loggers; +std::set > FileLogger::loggers; bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { @@ -37,10 +37,10 @@ bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry, if(entry[0][0].matches("File")) { if(entry[1].empty()) { if(!entry[0][1].empty()) { - FileLogger *logger = new FileLogger(entry[0][1]); + boost::shared_ptr logger(new FileLogger(entry[0][1])); loggers.insert(logger); - Core::LogManager::get()->registerLogger(static_cast(logger)); + Core::LogManager::get()->registerLogger(boost::static_pointer_cast(logger)); } else { Logger::logf(Logger::WARNING, "FileLogger: no filename given."); diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h index 04e2126..9b0f8e2 100644 --- a/src/modules/FileLogger/FileLogger.h +++ b/src/modules/FileLogger/FileLogger.h @@ -29,7 +29,7 @@ namespace Mad { namespace Modules { -class FileLogger : private Core::Logger, private Core::RemoteLogger { +class FileLogger : public Core::Logger, public Core::RemoteLogger { private: class ConfigHelper : public Core::Configurable { protected: @@ -40,7 +40,7 @@ class FileLogger : private Core::Logger, private Core::RemoteLogger { }; static ConfigHelper configHelper; - static std::set loggers; + static std::set > loggers; std::ofstream file; @@ -63,8 +63,8 @@ class FileLogger : private Core::Logger, private Core::RemoteLogger { static void unregisterConfigHelper() { Core::ConfigManager::get()->unregisterConfigurable(&configHelper); - for(std::set::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { - delete *logger; + for(std::set >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { + Core::LogManager::get()->unregisterLogger(boost::static_pointer_cast(*logger)); } loggers.clear(); -- cgit v1.2.3