diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/Backends/ConsoleLogger.h | 2 | ||||
-rw-r--r-- | src/Common/Backends/FileLogger.h | 2 | ||||
-rw-r--r-- | src/Common/Logger.cpp | 7 | ||||
-rw-r--r-- | src/Common/Logger.h | 21 |
4 files changed, 17 insertions, 15 deletions
diff --git a/src/Common/Backends/ConsoleLogger.h b/src/Common/Backends/ConsoleLogger.h index 7ae09a5..21b86ae 100644 --- a/src/Common/Backends/ConsoleLogger.h +++ b/src/Common/Backends/ConsoleLogger.h @@ -29,7 +29,7 @@ namespace Backends { class ConsoleLogger : public Logger { protected: - virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message) { + virtual void logMessage(MessageCategory, MessageLevel, const std::string &message) { std::cerr << message << std::endl; } diff --git a/src/Common/Backends/FileLogger.h b/src/Common/Backends/FileLogger.h index e31c019..98538ee 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(MessageCategory category, MessageLevel, const std::string &message) { + virtual void logMessage(MessageCategory, MessageLevel, const std::string &message) { file << message << std::endl; } diff --git a/src/Common/Logger.cpp b/src/Common/Logger.cpp index 859a77d..6206b59 100644 --- a/src/Common/Logger.cpp +++ b/src/Common/Logger.cpp @@ -86,5 +86,12 @@ void Logger::logf(const char *format, ...) { va_end(ap); } +void Logger::setAllCategories() { + static const MessageCategory categoryList[] = {SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL}; + + for(unsigned int i = 0; i < sizeof(categoryList)/sizeof(categoryList[0]); ++i) + setCategory(categoryList[i]); +} + } } diff --git a/src/Common/Logger.h b/src/Common/Logger.h index 360b746..ad75fbe 100644 --- a/src/Common/Logger.h +++ b/src/Common/Logger.h @@ -20,8 +20,6 @@ #ifndef MAD_COMMON_LOGGER_H_ #define MAD_COMMON_LOGGER_H_ -#define CATEGORYCOUNT 9 //Please insert the number of categories - #include <algorithm> #include <cstdarg> #include <list> @@ -36,6 +34,7 @@ class Logger { enum MessageLevel { CRITICAL, ERROR, WARNING, DEFAULT, VERBOSE, DEBUG }; + enum MessageCategory { SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL }; @@ -48,7 +47,7 @@ class Logger { static void logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap); protected: - Logger() : level(DEFAULT) {} + Logger() : level(DEFAULT) {setAllCategories();} virtual void logMessage(MessageCategory category, MessageLevel level, const std::string &message) = 0; public: @@ -77,23 +76,19 @@ class Logger { void setCategory(MessageCategory newCategory) { categories.insert(newCategory); } + void unsetCategory(MessageCategory oldCategory) { categories.erase(oldCategory); } - void setAllCategories() { - //each loop represents one category - for(int category = 1; category <= CATEGORYCOUNT; category++) { - categories.insert((MessageCategory)category); - } - } + + void setAllCategories(); + void unsetAllCategories() { categories.clear(); } + bool isCategorySet(MessageCategory category) { - if(categories.find(category) == categories.end()) - return false; - else - return true; + return (categories.find(category) != categories.end()); } MessageLevel getLevel() const { |