From 29d723d82834a30557136f7585254eaf3673ce69 Mon Sep 17 00:00:00 2001 From: Johannes Thorn Date: Sun, 28 Sep 2008 00:35:16 +0200 Subject: Logger gr?ndlich ?berarbeitet und den Networklogger um Timestamp erweitert. --- src/Common/Backends/ConsoleLogger.h | 9 +++++-- src/Common/Backends/FileLogger.h | 9 +++++-- src/Common/Logger.cpp | 4 ++- src/Common/Logger.h | 50 +++++-------------------------------- src/Common/Makefile.am | 4 +-- src/Common/Makefile.in | 9 ++++--- 6 files changed, 30 insertions(+), 55 deletions(-) (limited to 'src/Common') diff --git a/src/Common/Backends/ConsoleLogger.h b/src/Common/Backends/ConsoleLogger.h index 21b86ae..e1c8c43 100644 --- a/src/Common/Backends/ConsoleLogger.h +++ b/src/Common/Backends/ConsoleLogger.h @@ -21,17 +21,22 @@ #define MAD_COMMON_BACKENDS_CONSOLELOGGER_H_ #include "../Logger.h" +#include "../RemoteLogger.h" #include +#include namespace Mad { namespace Common { namespace Backends { -class ConsoleLogger : public Logger { +class ConsoleLogger : public Logger, public RemoteLogger { protected: - virtual void logMessage(MessageCategory, MessageLevel, const std::string &message) { + virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message) { std::cerr << message << std::endl; } + virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message, const std::string &messageSource) { + std::cerr << message << " from "<< messageSource << std::endl; + } public: ConsoleLogger() {} diff --git a/src/Common/Backends/FileLogger.h b/src/Common/Backends/FileLogger.h index 98538ee..59d2e16 100644 --- a/src/Common/Backends/FileLogger.h +++ b/src/Common/Backends/FileLogger.h @@ -21,20 +21,25 @@ #define MAD_COMMON_BACKENDS_FILELOGGER_H_ #include "../Logger.h" +#include "../RemoteLogger.h" #include +#include namespace Mad { namespace Common { namespace Backends { -class FileLogger : public Logger { +class FileLogger : public Logger, public RemoteLogger { private: std::ofstream file; protected: - virtual void logMessage(MessageCategory, MessageLevel, const std::string &message) { + virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message) { file << message << std::endl; } + virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message, const std::string &messageSource) { + file << message << " from "<< messageSource << std::endl; + } public: FileLogger(const std::string &filename) diff --git a/src/Common/Logger.cpp b/src/Common/Logger.cpp index f87d41b..a7d3bd1 100644 --- a/src/Common/Logger.cpp +++ b/src/Common/Logger.cpp @@ -19,6 +19,7 @@ #include "Logger.h" #include +#include namespace Mad { namespace Common { @@ -55,9 +56,10 @@ void Logger::logfv(MessageCategory category, MessageLevel level, const char *for } void Logger::log(MessageCategory category, MessageLevel level, const std::string &message) { + time_t messageTimestamp = std::time(NULL); for(std::list::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { if((*logger)->getLevel() >= level && (*logger)->isCategorySet(category)) - (*logger)->logMessage(category, level, message); + (*logger)->logMessage(category, level, messageTimestamp, message); } } diff --git a/src/Common/Logger.h b/src/Common/Logger.h index 593fd7a..1fff654 100644 --- a/src/Common/Logger.h +++ b/src/Common/Logger.h @@ -20,35 +20,24 @@ #ifndef MAD_COMMON_LOGGER_H_ #define MAD_COMMON_LOGGER_H_ +#include "LoggerBase.h" #include -#include #include #include -#include +#include +#include namespace Mad { namespace Common { -class Logger { - public: - enum MessageLevel { - CRITICAL, ERROR, WARNING, DEFAULT, VERBOSE, DEBUG - }; - - enum MessageCategory { - SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL - }; - +class Logger : public LoggerBase { private: static std::list loggers; - std::bitset<16> categories; - MessageLevel level; static void logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap); protected: - Logger() : level(DEFAULT) {setAllCategories();} - virtual void logMessage(MessageCategory category, MessageLevel level, const std::string &message) = 0; + virtual void logMessage(MessageCategory category, MessageLevel level, time_t messageTimestamp, const std::string &message) = 0; public: static void log(MessageCategory category, MessageLevel level, const std::string &message); @@ -77,34 +66,7 @@ class Logger { loggers.erase(it); } - void setCategory(MessageCategory newCategory) { - categories.set(newCategory); - } - - void unsetCategory(MessageCategory oldCategory) { - categories.reset(oldCategory); - } - - void setAllCategories() { - categories.set(); - } - - void unsetAllCategories() { - categories.reset(); - } - - bool isCategorySet(MessageCategory category) { - return categories.test(category); - } - - MessageLevel getLevel() const { - return level; - } - - void setLevel(MessageLevel newLevel) { - level = newLevel; - } - + Logger() {} virtual ~Logger() {} }; diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am index d232f0b..be2f08e 100644 --- a/src/Common/Makefile.am +++ b/src/Common/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = Backends Requests RequestHandlers noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = ConfigManager.cpp Exception.cpp Logger.cpp RequestManager.cpp SystemBackend.cpp Util.cpp +libcommon_la_SOURCES = RemoteLogger.cpp Logger.cpp ConfigManager.cpp Exception.cpp RequestManager.cpp SystemBackend.cpp Util.cpp libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la -noinst_HEADERS = ConfigManager.h Exception.h HostInfo.h Logger.h Request.h RequestBase.h RequestHandler.h RequestManager.h SystemBackend.h Util.h +noinst_HEADERS = LoggerBase.h RemoteLogger.h Logger.h ConfigManager.h Exception.h HostInfo.h Request.h RequestBase.h RequestHandler.h RequestManager.h SystemBackend.h Util.h diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in index e50a6d9..40cb554 100644 --- a/src/Common/Makefile.in +++ b/src/Common/Makefile.in @@ -49,8 +49,8 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libcommon_la_DEPENDENCIES = Backends/libbackends.la \ Requests/librequests.la RequestHandlers/librequesthandlers.la -am_libcommon_la_OBJECTS = ConfigManager.lo Exception.lo Logger.lo \ - RequestManager.lo SystemBackend.lo Util.lo +am_libcommon_la_OBJECTS = RemoteLogger.lo Logger.lo ConfigManager.lo \ + Exception.lo RequestManager.lo SystemBackend.lo Util.lo libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -200,9 +200,9 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = Backends Requests RequestHandlers noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = ConfigManager.cpp Exception.cpp Logger.cpp RequestManager.cpp SystemBackend.cpp Util.cpp +libcommon_la_SOURCES = RemoteLogger.cpp Logger.cpp ConfigManager.cpp Exception.cpp RequestManager.cpp SystemBackend.cpp Util.cpp libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la -noinst_HEADERS = ConfigManager.h Exception.h HostInfo.h Logger.h Request.h RequestBase.h RequestHandler.h RequestManager.h SystemBackend.h Util.h +noinst_HEADERS = LoggerBase.h RemoteLogger.h Logger.h ConfigManager.h Exception.h HostInfo.h Request.h RequestBase.h RequestHandler.h RequestManager.h SystemBackend.h Util.h all: all-recursive .SUFFIXES: @@ -257,6 +257,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Exception.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Logger.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RemoteLogger.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackend.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Plo@am__quote@ -- cgit v1.2.3