diff options
-rw-r--r-- | src/Common/Backends/ConsoleLogger.cpp | 33 | ||||
-rw-r--r-- | src/Common/Backends/ConsoleLogger.h | 5 | ||||
-rw-r--r-- | src/Common/Backends/FileLogger.cpp | 32 | ||||
-rw-r--r-- | src/Common/Backends/FileLogger.h | 4 | ||||
-rw-r--r-- | src/Common/Backends/Makefile.am | 2 | ||||
-rw-r--r-- | src/Common/Backends/Makefile.in | 7 | ||||
-rw-r--r-- | src/Common/Logger.cpp | 7 | ||||
-rw-r--r-- | src/Common/Logger.h | 38 |
8 files changed, 41 insertions, 87 deletions
diff --git a/src/Common/Backends/ConsoleLogger.cpp b/src/Common/Backends/ConsoleLogger.cpp deleted file mode 100644 index 503bca7..0000000 --- a/src/Common/Backends/ConsoleLogger.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ConsoleLogger.cpp - * - * Copyright (C) 2008 Johannes Thorn <dante@g4t3.de> - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "ConsoleLogger.h" -#include <iostream> - -namespace Mad { -namespace Common { -namespace Backends { - -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 ee0b51e..7ae09a5 100644 --- a/src/Common/Backends/ConsoleLogger.h +++ b/src/Common/Backends/ConsoleLogger.h @@ -21,6 +21,7 @@ #define MAD_COMMON_BACKENDS_CONSOLELOGGER_H_ #include "../Logger.h" +#include <iostream> namespace Mad { namespace Common { @@ -28,7 +29,9 @@ namespace Backends { class ConsoleLogger : public Logger { protected: - virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message); + virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message) { + std::cerr << message << std::endl; + } public: ConsoleLogger() {} diff --git a/src/Common/Backends/FileLogger.cpp b/src/Common/Backends/FileLogger.cpp deleted file mode 100644 index 8d95da5..0000000 --- a/src/Common/Backends/FileLogger.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * FileLogger.cpp - * - * Copyright (C) 2008 Johannes Thorn <dante@g4t3.de> - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "FileLogger.h" - -namespace Mad { -namespace Common { -namespace Backends { - -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 3626fed..e31c019 100644 --- a/src/Common/Backends/FileLogger.h +++ b/src/Common/Backends/FileLogger.h @@ -32,7 +32,9 @@ class FileLogger : public Logger { std::ofstream file; protected: - virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message); + virtual void logMessage(MessageCategory category, MessageLevel, const std::string &message) { + file << message << std::endl; + } public: FileLogger(const std::string &filename) diff --git a/src/Common/Backends/Makefile.am b/src/Common/Backends/Makefile.am index 5a6e325..26ec0f0 100644 --- a/src/Common/Backends/Makefile.am +++ b/src/Common/Backends/Makefile.am @@ -1,5 +1,5 @@ noinst_LTLIBRARIES = libbackends.la -libbackends_la_SOURCES = ConsoleLogger.cpp FileLogger.cpp SystemBackendProc.cpp +libbackends_la_SOURCES = SystemBackendProc.cpp noinst_HEADERS = ConsoleLogger.h FileLogger.h SystemBackendProc.h diff --git a/src/Common/Backends/Makefile.in b/src/Common/Backends/Makefile.in index ad490ee..4a48c24 100644 --- a/src/Common/Backends/Makefile.in +++ b/src/Common/Backends/Makefile.in @@ -48,8 +48,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libbackends_la_LIBADD = -am_libbackends_la_OBJECTS = ConsoleLogger.lo FileLogger.lo \ - SystemBackendProc.lo +am_libbackends_la_OBJECTS = SystemBackendProc.lo libbackends_la_OBJECTS = $(am_libbackends_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -188,7 +187,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = libbackends.la -libbackends_la_SOURCES = ConsoleLogger.cpp FileLogger.cpp SystemBackendProc.cpp +libbackends_la_SOURCES = SystemBackendProc.cpp noinst_HEADERS = ConsoleLogger.h FileLogger.h SystemBackendProc.h all: all-am @@ -241,8 +240,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleLogger.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileLogger.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendProc.Plo@am__quote@ .cpp.o: diff --git a/src/Common/Logger.cpp b/src/Common/Logger.cpp index 199688d..859a77d 100644 --- a/src/Common/Logger.cpp +++ b/src/Common/Logger.cpp @@ -55,8 +55,9 @@ void Logger::logfv(MessageCategory category, MessageLevel level, const char *for } void Logger::log(MessageCategory category, MessageLevel level, const std::string &message) { + //TODO Category for(std::list<Logger*>::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { - if((*logger)->getLevel() >= level && (*logger)->getCategory() == category) + if((*logger)->getLevel() >= level && (*logger)->isCategorySet(category)) (*logger)->logMessage(category, level, message); } } @@ -73,7 +74,7 @@ void Logger::logf(MessageLevel level, const char *format, ...) { va_list ap; va_start(ap, format); - logfv(ALL, level, format, ap); + logfv(GENERAL, level, format, ap); va_end(ap); } @@ -81,7 +82,7 @@ void Logger::logf(const char *format, ...) { va_list ap; va_start(ap, format); - logfv(ALL, DEFAULT, format, ap); + logfv(GENERAL, DEFAULT, format, ap); va_end(ap); } diff --git a/src/Common/Logger.h b/src/Common/Logger.h index ba14347..360b746 100644 --- a/src/Common/Logger.h +++ b/src/Common/Logger.h @@ -20,10 +20,13 @@ #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> #include <string> +#include <set> namespace Mad { namespace Common { @@ -34,28 +37,27 @@ class Logger { CRITICAL, ERROR, WARNING, DEFAULT, VERBOSE, DEBUG }; enum MessageCategory { - ALL, SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL + SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL }; private: static std::list<Logger*> loggers; - MessageCategory category; + std::set<MessageCategory> categories; MessageLevel level; static void logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap); protected: - Logger() : level(DEFAULT), category(ALL) {} - + Logger() : level(DEFAULT) {} virtual void logMessage(MessageCategory category, MessageLevel level, const std::string &message) = 0; public: static void log(MessageCategory category, MessageLevel level, const std::string &message); static void log(MessageLevel level, const std::string &message) { - log(ALL, level, message); + log(GENERAL, level, message); } static void log(const std::string &message) { - log(ALL, DEFAULT, message); + log(GENERAL, DEFAULT, message); } static void logf(MessageCategory category, MessageLevel level, const char *format, ...); @@ -72,12 +74,26 @@ class Logger { loggers.erase(it); } - MessageCategory getCategory() const { - return category; - } - void setCategory(MessageCategory newCategory) { - category = 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 unsetAllCategories() { + categories.clear(); + } + bool isCategorySet(MessageCategory category) { + if(categories.find(category) == categories.end()) + return false; + else + return true; } MessageLevel getLevel() const { |