From 7890312d0a850ffc5be20d078d7e8f2d148dca3e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 31 Aug 2009 21:21:09 +0200 Subject: =?UTF-8?q?LogManager=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/FileLogger/FileLogger.h | 13 ++++++------- src/modules/FileLogger/Module.cpp | 23 ++++++++++++++++++----- src/modules/FileLogger/Module.h | 2 ++ 3 files changed, 26 insertions(+), 12 deletions(-) (limited to 'src/modules/FileLogger') diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h index 0ee9ad7..c202e4b 100644 --- a/src/modules/FileLogger/FileLogger.h +++ b/src/modules/FileLogger/FileLogger.h @@ -23,22 +23,21 @@ #include #include -#include namespace Mad { namespace Modules { namespace FileLogger { -class FileLogger : public Core::Logger, public Core::RemoteLogger { +class FileLogger : public Core::Logger { private: std::ofstream file; protected: - virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message) { - file << message << std::endl; - } - virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &messageSource) { - file << message << " from "<< messageSource << std::endl; + virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &source) { + if(source.empty()) + file << message << std::endl; + else + file << message << " from "<< source << std::endl; } public: diff --git a/src/modules/FileLogger/Module.cpp b/src/modules/FileLogger/Module.cpp index e715386..88d475c 100644 --- a/src/modules/FileLogger/Module.cpp +++ b/src/modules/FileLogger/Module.cpp @@ -30,21 +30,34 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { if(handled) return false; - if(entry[0].getKey().matches("Logger")) { + if(entry[0].getKey().matches("Log")) { if(entry[0][0].matches("File")) { if(entry[1].empty()) { if(!entry[0][1].empty()) { - boost::shared_ptr logger(new FileLogger(entry[0][1])); + lastLogger.reset(new FileLogger(entry[0][1])); - loggers.insert(logger); - application->getLogManager()->registerLogger(boost::static_pointer_cast(logger)); + loggers.insert(lastLogger); + application->getLogManager()->registerLogger(lastLogger); } else { - application->logf(Core::LoggerBase::LOG_WARNING, "FileLogger: no filename given."); + lastLogger.reset(); + application->logf(Core::Logger::LOG_WARNING, "FileLogger: no filename given."); } return true; } + else if(entry[1].getKey().matches("Level")) { + if(entry[2].empty()) { + try { + 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].c_str()); + } + + return true; + } + } } } diff --git a/src/modules/FileLogger/Module.h b/src/modules/FileLogger/Module.h index b45dd8c..8cf54a1 100644 --- a/src/modules/FileLogger/Module.h +++ b/src/modules/FileLogger/Module.h @@ -39,6 +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); -- cgit v1.2.3