diff options
Diffstat (limited to 'src/modules/FileLogger')
-rw-r--r-- | src/modules/FileLogger/FileLogger.h | 13 | ||||
-rw-r--r-- | src/modules/FileLogger/Module.cpp | 23 | ||||
-rw-r--r-- | src/modules/FileLogger/Module.h | 2 |
3 files changed, 26 insertions, 12 deletions
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 <fstream> #include <Core/Logger.h> -#include <Core/RemoteLogger.h> 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<FileLogger> logger(new FileLogger(entry[0][1])); + lastLogger.reset(new FileLogger(entry[0][1])); - loggers.insert(logger); - application->getLogManager()->registerLogger(boost::static_pointer_cast<Core::Logger>(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<boost::shared_ptr<FileLogger> > loggers; + boost::shared_ptr<FileLogger> lastLogger; + protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); |