summaryrefslogtreecommitdiffstats
path: root/src/Common/LogManager.h
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-10-27 22:41:06 +0100
committerMatthias Schiffer <matthias@gamezock.de>2008-10-27 22:41:06 +0100
commit2b83ae7c71dc706fb4fd7b4efc4a8ffee8dfe522 (patch)
tree4f63c64041fd93255105493fd444a65ad0761b9b /src/Common/LogManager.h
parentb58831e5eec4d0595099b8e9c2979b157fe37041 (diff)
downloadmad-2b83ae7c71dc706fb4fd7b4efc4a8ffee8dfe522.tar
mad-2b83ae7c71dc706fb4fd7b4efc4a8ffee8dfe522.zip
Neues Initialisierung-Framework hinzugef?gt
Diffstat (limited to 'src/Common/LogManager.h')
-rw-r--r--src/Common/LogManager.h98
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_ */