diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-28 19:09:22 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-28 19:09:22 +0200 |
commit | 86e5f80837ad55932f2469d79d9e6b6bb07cf5ed (patch) | |
tree | 818ab757a8ae964751190daad5a7fd2cd8f21a04 /src/modules/FileLogger | |
parent | a7a285eb61dd83afc892bc1d64ffe14b9f1426a3 (diff) | |
download | mad-86e5f80837ad55932f2469d79d9e6b6bb07cf5ed.tar mad-86e5f80837ad55932f2469d79d9e6b6bb07cf5ed.zip |
Implemented new ConfigManager
Diffstat (limited to 'src/modules/FileLogger')
-rw-r--r-- | src/modules/FileLogger/Module.cpp | 57 | ||||
-rw-r--r-- | src/modules/FileLogger/Module.h | 4 |
2 files changed, 26 insertions, 35 deletions
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<const Core::ConfigEntry*> 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<const Core::ConfigEntry*>::iterator entry = entries.begin(); entry != entries.end(); ++entry) { + const std::vector<Core::String> &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<FileLogger> logger(new FileLogger(values[1].toLocale())); + loggers.insert(logger); + application->getLogManager()->registerLogger(logger); + + bool remote = false; + for(std::vector<Core::String>::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<boost::shared_ptr<FileLogger> > loggers; - boost::shared_ptr<FileLogger> lastLogger; - protected: - virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); + virtual void configure(); public: Module(Common::Application *application0) : application(application0) { |