From 86e5f80837ad55932f2469d79d9e6b6bb07cf5ed Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 28 Sep 2009 19:09:22 +0200 Subject: Implemented new ConfigManager --- src/modules/FileLogger/Module.cpp | 57 +++++++++++++++++---------------------- src/modules/FileLogger/Module.h | 4 +-- 2 files changed, 26 insertions(+), 35 deletions(-) (limited to 'src/modules/FileLogger') diff --git a/src/modules/FileLogger/Module.cpp b/src/modules/FileLogger/Module.cpp index d8a302c..25a54b4 100644 --- a/src/modules/FileLogger/Module.cpp +++ b/src/modules/FileLogger/Module.cpp @@ -26,45 +26,38 @@ namespace Mad { namespace Modules { namespace FileLogger { -bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { - if(handled) - return false; +void Module::configure() { + std::vector entries = application->getConfigManager()->getEntries("Log"); - if(entry[0].getKey().matches("Log")) { - if(entry[0][0].matches("File")) { - if(entry[1].isEmpty()) { - if(!entry[0][1].isEmpty()) { - lastLogger.reset(new FileLogger(entry[0][1].toLocale())); + for(std::vector::iterator entry = entries.begin(); entry != entries.end(); ++entry) { + const std::vector &values = (*entry)->getValues(); - loggers.insert(lastLogger); - application->getLogManager()->registerLogger(lastLogger); - } - else { - lastLogger.reset(); - application->logf(Core::Logger::LOG_WARNING, "FileLogger: no filename given."); - } + if(values.size() < 2 || !values.front().matches("File")) + continue; - return true; - } - else if(entry[1].getKey().matches("Level")) { - if(entry[2].isEmpty()) { - try { - if(entry[1][0].matches("remote")) - lastLogger->setRemoteLevel(Core::LogManager::parseLevel(entry[1][1])); - else - lastLogger->setLevel(Core::LogManager::parseLevel(entry[1][0])); - } - catch(Core::Exception e) { - application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].toLocale().c_str()); - } + boost::shared_ptr logger(new FileLogger(values[1].toLocale())); + loggers.insert(logger); + application->getLogManager()->registerLogger(logger); + + bool remote = false; + for(std::vector::const_iterator value = values.begin()+2; value != values.end(); ++value) { + if(value->matches("remote")) + remote = true; + } - return true; - } + Core::String level = (*entry)->get("Level"); + if(!level.isEmpty()) { + try { + if(remote) + logger->setRemoteLevel(Core::LogManager::parseLevel(level)); + else + logger->setLevel(Core::LogManager::parseLevel(level)); + } + catch(Core::Exception e) { + application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", level.toLocale().c_str()); } } } - - return false; } } diff --git a/src/modules/FileLogger/Module.h b/src/modules/FileLogger/Module.h index 8cf54a1..5cbd1df 100644 --- a/src/modules/FileLogger/Module.h +++ b/src/modules/FileLogger/Module.h @@ -39,10 +39,8 @@ class Module : public Common::Module, private Core::Configurable { std::set > loggers; - boost::shared_ptr lastLogger; - protected: - virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); + virtual void configure(); public: Module(Common::Application *application0) : application(application0) { -- cgit v1.2.3