summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-31 23:10:27 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-31 23:10:27 +0200
commit85c914d0087458009ec74bbfdd4f7d8345aa1d2c (patch)
treee0bd366a27e1d2e01570024cba94eeb2dc07c350 /src/Core
parent7890312d0a850ffc5be20d078d7e8f2d148dca3e (diff)
downloadmad-85c914d0087458009ec74bbfdd4f7d8345aa1d2c.tar
mad-85c914d0087458009ec74bbfdd4f7d8345aa1d2c.zip
Logger: Unterstützung für RemoteLogger
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/Configurable.h2
-rw-r--r--src/Core/LogManager.cpp8
-rw-r--r--src/Core/Logger.h51
3 files changed, 54 insertions, 7 deletions
diff --git a/src/Core/Configurable.h b/src/Core/Configurable.h
index f385e10..c526379 100644
--- a/src/Core/Configurable.h
+++ b/src/Core/Configurable.h
@@ -20,8 +20,6 @@
#ifndef MAD_CORE_CONFIGURABLE_H_
#define MAD_CORE_CONFIGURABLE_H_
-#include "export.h"
-
namespace Mad {
namespace Core {
diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp
index 8fe7428..af3e0ba 100644
--- a/src/Core/LogManager.cpp
+++ b/src/Core/LogManager.cpp
@@ -84,7 +84,10 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
else if(entry[1].getKey().matches("Level")) {
if(entry[2].empty()) {
try {
- consoleLogger->setLevel(parseLevel(entry[1][0]));
+ if(boost::algorithm::to_lower_copy(static_cast<std::string>(entry[1][0])) == "remote")
+ consoleLogger->setRemoteLevel(parseLevel(entry[1][1]));
+ else
+ consoleLogger->setLevel(parseLevel(entry[1][0]));
}
catch(Core::Exception e) {
application->logf(Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].c_str());
@@ -142,8 +145,7 @@ void LogManager::loggerThread() {
{
boost::lock_guard<boost::mutex> loggerLock(loggerMutex);
for(std::set<boost::shared_ptr<Logger> >::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, message.source);
+ (*logger)->log(message.category, message.level, message.timestamp, message.message, message.source);
}
}
diff --git a/src/Core/Logger.h b/src/Core/Logger.h
index 24582bc..a43b340 100644
--- a/src/Core/Logger.h
+++ b/src/Core/Logger.h
@@ -34,7 +34,7 @@ class Logger {
friend class LogManager;
enum MessageLevel {
- LOG_CRITICAL, LOG_ERROR, LOG_WARNING, LOG_DEFAULT, LOG_VERBOSE, LOG_DEBUG
+ LOG_CRITICAL = 1, LOG_ERROR, LOG_WARNING, LOG_DEFAULT, LOG_VERBOSE, LOG_DEBUG
};
enum MessageCategory {
@@ -45,10 +45,21 @@ class Logger {
std::bitset<16> categories;
MessageLevel level;
+ std::bitset<16> remoteCategories;
+ MessageLevel remoteLevel;
+
+ bool remote;
+
protected:
- Logger() : level(LOG_DEFAULT) {setAllCategories();}
+ Logger() : level(LOG_DEFAULT), remoteLevel(LOG_DEFAULT) {setAllCategories(); setAllRemoteCategories(); remote = false;}
virtual ~Logger() {}
+ void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) {
+ if((source.empty() && getLevel() >= level && isCategorySet(category))
+ || (!source.empty() && remote && getRemoteLevel() >= level && isRemoteCategorySet(category)))
+ logMessage(category, level, timestamp, message, source);
+ }
+
virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) = 0;
public:
@@ -72,6 +83,32 @@ class Logger {
return categories.test(category);
}
+
+ void setRemoteCategory(MessageCategory newCategory) {
+ remote = true;
+ remoteCategories.set(newCategory);
+ }
+
+ void unsetRemoteCategory(MessageCategory oldCategory) {
+ remote = true;
+ remoteCategories.reset(oldCategory);
+ }
+
+ void setAllRemoteCategories() {
+ remote = true;
+ remoteCategories.set();
+ }
+
+ void unsetAllRemoteCategories() {
+ remote = true;
+ remoteCategories.reset();
+ }
+
+ bool isRemoteCategorySet(MessageCategory category) const {
+ return remoteCategories.test(category);
+ }
+
+
MessageLevel getLevel() const {
return level;
}
@@ -79,6 +116,16 @@ class Logger {
void setLevel(MessageLevel newLevel) {
level = newLevel;
}
+
+
+ MessageLevel getRemoteLevel() const {
+ return remoteLevel;
+ }
+
+ void setRemoteLevel(MessageLevel newLevel) {
+ remote = true;
+ remoteLevel = newLevel;
+ }
};
}