From 2b83ae7c71dc706fb4fd7b4efc4a8ffee8dfe522 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 27 Oct 2008 22:41:06 +0100 Subject: Neues Initialisierung-Framework hinzugef?gt --- src/Common/LogManager.h | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/Common/LogManager.h (limited to 'src/Common/LogManager.h') diff --git a/src/Common/LogManager.h b/src/Common/LogManager.h new file mode 100644 index 0000000..c1bba9f --- /dev/null +++ b/src/Common/LogManager.h @@ -0,0 +1,98 @@ +/* + * LogManager.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#ifndef MAD_COMMON_LOGMANAGER_H_ +#define MAD_COMMON_LOGMANAGER_H_ + +#include "Configurable.h" +#include "Initializable.h" +#include "Logger.h" +#include "RemoteLogger.h" +#include "SharedPtr.h" + +#include +#include +#include + +namespace Mad { +namespace Common { + +class LogManager : public Initializable, public Configurable { + private: + typedef LoggerBase::MessageCategory MessageCategory; + typedef LoggerBase::MessageLevel MessageLevel; + + struct Message { + MessageCategory category; + MessageLevel level; + time_t timestamp; + std::string message; + }; + + struct RemoteMessage { + MessageCategory category; + MessageLevel level; + time_t timestamp; + std::string message; + std::string source; + }; + + static LogManager logManager; + + std::set > loggers; + std::set > remoteLoggers; + + std::auto_ptr > messageQueue; + std::auto_ptr > remoteMessageQueue; + + LogManager() : messageQueue(new std::queue()), remoteMessageQueue(new std::queue()) {} + + protected: + virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled); + virtual void configFinished(); + + public: + void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message); + void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source); + + void registerLogger(SharedPtr logger) { + loggers.insert(logger); + } + + void unregisterLogger(SharedPtr logger) { + loggers.erase(logger); + } + + void registerLogger(SharedPtr logger) { + remoteLoggers.insert(logger); + } + + void unregisterLogger(SharedPtr logger) { + remoteLoggers.erase(logger); + } + + static LogManager *getLogManager() { + return &logManager; + } +}; + +} +} + +#endif /* MAD_COMMON_LOGMANAGER_H_ */ -- cgit v1.2.3