diff options
Diffstat (limited to 'src/Common/LogManager.h')
-rw-r--r-- | src/Common/LogManager.h | 98 |
1 files changed, 98 insertions, 0 deletions
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 <matthias@gamezock.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/>. + */ + +#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 <memory> +#include <queue> +#include <set> + +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<SharedPtr<Logger> > loggers; + std::set<SharedPtr<RemoteLogger> > remoteLoggers; + + std::auto_ptr<std::queue<Message> > messageQueue; + std::auto_ptr<std::queue<RemoteMessage> > remoteMessageQueue; + + LogManager() : messageQueue(new std::queue<Message>()), remoteMessageQueue(new std::queue<RemoteMessage>()) {} + + 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> logger) { + loggers.insert(logger); + } + + void unregisterLogger(SharedPtr<Logger> logger) { + loggers.erase(logger); + } + + void registerLogger(SharedPtr<RemoteLogger> logger) { + remoteLoggers.insert(logger); + } + + void unregisterLogger(SharedPtr<RemoteLogger> logger) { + remoteLoggers.erase(logger); + } + + static LogManager *getLogManager() { + return &logManager; + } +}; + +} +} + +#endif /* MAD_COMMON_LOGMANAGER_H_ */ |