summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorJohannes Thorn <dante@g4t3.de>2008-09-21 23:56:17 +0200
committerJohannes Thorn <dante@g4t3.de>2008-09-21 23:56:17 +0200
commitfe6d06a7df225e79756229131f128981bbb83b40 (patch)
tree4bf4a8337443f242ab4dfdf233b213a489be22d7 /src/Common
parent91e4259c737e8ba5c6d5bc12b710f124a228e912 (diff)
downloadmad-fe6d06a7df225e79756229131f128981bbb83b40.tar
mad-fe6d06a7df225e79756229131f128981bbb83b40.zip
Log Kategorien hinzugef?gt und Loggerimplementation angepasst.
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Backends/ConsoleLogger.cpp2
-rw-r--r--src/Common/Backends/ConsoleLogger.h2
-rw-r--r--src/Common/Backends/FileLogger.cpp2
-rw-r--r--src/Common/Backends/FileLogger.h2
-rw-r--r--src/Common/Logger.cpp22
-rw-r--r--src/Common/Logger.h26
6 files changed, 40 insertions, 16 deletions
diff --git a/src/Common/Backends/ConsoleLogger.cpp b/src/Common/Backends/ConsoleLogger.cpp
index 4bfa93b..503bca7 100644
--- a/src/Common/Backends/ConsoleLogger.cpp
+++ b/src/Common/Backends/ConsoleLogger.cpp
@@ -24,7 +24,7 @@ namespace Mad {
namespace Common {
namespace Backends {
-void ConsoleLogger::logMessage(MessageLevel, const std::string &message) {
+void ConsoleLogger::logMessage(MessageCategory category, MessageLevel, const std::string &message) {
std::cerr << message << std::endl;
}
diff --git a/src/Common/Backends/ConsoleLogger.h b/src/Common/Backends/ConsoleLogger.h
index 72fc179..ee0b51e 100644
--- a/src/Common/Backends/ConsoleLogger.h
+++ b/src/Common/Backends/ConsoleLogger.h
@@ -28,7 +28,7 @@ namespace Backends {
class ConsoleLogger : public Logger {
protected:
- virtual void logMessage(MessageLevel, const std::string &message);
+ virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message);
public:
ConsoleLogger() {}
diff --git a/src/Common/Backends/FileLogger.cpp b/src/Common/Backends/FileLogger.cpp
index b0bd57b..8d95da5 100644
--- a/src/Common/Backends/FileLogger.cpp
+++ b/src/Common/Backends/FileLogger.cpp
@@ -23,7 +23,7 @@ namespace Mad {
namespace Common {
namespace Backends {
-void FileLogger::logMessage(MessageLevel, const std::string &message) {
+void FileLogger::logMessage(MessageCategory category, MessageLevel, const std::string &message) {
file << message << std::endl;
}
diff --git a/src/Common/Backends/FileLogger.h b/src/Common/Backends/FileLogger.h
index 09946df..3626fed 100644
--- a/src/Common/Backends/FileLogger.h
+++ b/src/Common/Backends/FileLogger.h
@@ -32,7 +32,7 @@ class FileLogger : public Logger {
std::ofstream file;
protected:
- virtual void logMessage(MessageLevel, const std::string &message);
+ virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message);
public:
FileLogger(const std::string &filename)
diff --git a/src/Common/Logger.cpp b/src/Common/Logger.cpp
index 22748d1..199688d 100644
--- a/src/Common/Logger.cpp
+++ b/src/Common/Logger.cpp
@@ -26,7 +26,7 @@ namespace Common {
std::list<Logger*> Logger::loggers;
-void Logger::logfv(MessageLevel level, const char *format, va_list ap) {
+void Logger::logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap) {
int size = 100;
char *buf = (char*)std::malloc(size);
@@ -39,7 +39,7 @@ void Logger::logfv(MessageLevel level, const char *format, va_list ap) {
va_end(ap2);
if(n > -1 && n < size) {
- log(level, buf);
+ log(category, level, buf);
std::free(buf);
return;
}
@@ -54,18 +54,26 @@ void Logger::logfv(MessageLevel level, const char *format, va_list ap) {
}
-void Logger::log(MessageLevel level, const std::string &message) {
+void Logger::log(MessageCategory category, MessageLevel level, const std::string &message) {
for(std::list<Logger*>::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
- if((*logger)->getLevel() >= level)
- (*logger)->logMessage(level, message);
+ if((*logger)->getLevel() >= level && (*logger)->getCategory() == category)
+ (*logger)->logMessage(category, level, message);
}
}
+void Logger::logf(MessageCategory category, MessageLevel level, const char *format, ...) {
+ va_list ap;
+
+ va_start(ap, format);
+ logfv(category, level, format, ap);
+ va_end(ap);
+}
+
void Logger::logf(MessageLevel level, const char *format, ...) {
va_list ap;
va_start(ap, format);
- logfv(level, format, ap);
+ logfv(ALL, level, format, ap);
va_end(ap);
}
@@ -73,7 +81,7 @@ void Logger::logf(const char *format, ...) {
va_list ap;
va_start(ap, format);
- logfv(DEFAULT, format, ap);
+ logfv(ALL, DEFAULT, format, ap);
va_end(ap);
}
diff --git a/src/Common/Logger.h b/src/Common/Logger.h
index f1cd33d..ba14347 100644
--- a/src/Common/Logger.h
+++ b/src/Common/Logger.h
@@ -33,24 +33,32 @@ class Logger {
enum MessageLevel {
CRITICAL, ERROR, WARNING, DEFAULT, VERBOSE, DEBUG
};
+ enum MessageCategory {
+ ALL, SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL
+ };
private:
static std::list<Logger*> loggers;
+ MessageCategory category;
MessageLevel level;
- static void logfv(MessageLevel level, const char *format, va_list ap);
+ static void logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap);
protected:
- Logger() : level(DEFAULT) {}
+ Logger() : level(DEFAULT), category(ALL) {}
- virtual void logMessage(MessageLevel level, const std::string &message) = 0;
+ virtual void logMessage(MessageCategory category, MessageLevel level, const std::string &message) = 0;
public:
- static void log(MessageLevel level, const std::string &message);
+ static void log(MessageCategory category, MessageLevel level, const std::string &message);
+ static void log(MessageLevel level, const std::string &message) {
+ log(ALL, level, message);
+ }
static void log(const std::string &message) {
- log(DEFAULT, message);
+ log(ALL, DEFAULT, message);
}
+ static void logf(MessageCategory category, MessageLevel level, const char *format, ...);
static void logf(MessageLevel level, const char *format, ...);
static void logf(const char *format, ...);
@@ -64,6 +72,14 @@ class Logger {
loggers.erase(it);
}
+ MessageCategory getCategory() const {
+ return category;
+ }
+
+ void setCategory(MessageCategory newCategory) {
+ category = newCategory;
+ }
+
MessageLevel getLevel() const {
return level;
}