summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-12-22 01:10:47 +0100
committerMatthias Schiffer <matthias@gamezock.de>2008-12-22 01:10:47 +0100
commit33ecd8fa230f1b50165121747c1e68a922c08909 (patch)
tree92bf6760be2385a713fd4ca6f88f7fd1c5f77d55 /src/modules
parent389960211861736ef321df82f6abcb59f6302897 (diff)
downloadmad-33ecd8fa230f1b50165121747c1e68a922c08909.tar
mad-33ecd8fa230f1b50165121747c1e68a922c08909.zip
FileLogger als Modul ausgelagert
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/FileLogger.cpp73
-rw-r--r--src/modules/FileLogger.h77
-rw-r--r--src/modules/Makefile.am15
-rw-r--r--src/modules/Makefile.in26
4 files changed, 178 insertions, 13 deletions
diff --git a/src/modules/FileLogger.cpp b/src/modules/FileLogger.cpp
new file mode 100644
index 0000000..5e0c021
--- /dev/null
+++ b/src/modules/FileLogger.cpp
@@ -0,0 +1,73 @@
+/*
+ * FileLogger.cpp
+ *
+ * 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/>.
+ */
+
+#include "FileLogger.h"
+
+#include <Common/ConfigEntry.h>
+
+#define init FileLogger_LTX_init
+#define deinit FileLogger_LTX_deinit
+
+
+namespace Mad {
+namespace Modules {
+
+FileLogger::ConfigHelper FileLogger::configHelper;
+std::set<FileLogger*> FileLogger::loggers;
+
+
+bool FileLogger::ConfigHelper::handleConfigEntry(const Common::ConfigEntry &entry, bool handled) {
+ if(handled)
+ return false;
+
+ if(entry[0].getKey().matches("Logger")) {
+ if(entry[0][0].matches("File")) {
+ if(entry[1].empty()) {
+ if(!entry[0][1].empty()) {
+ FileLogger *logger = new FileLogger(entry[0][1]);
+
+ loggers.insert(logger);
+ Common::LogManager::get()->registerLogger(static_cast<Logger*>(logger));
+ }
+ else {
+ Logger::logf(Logger::WARNING, "FileLogger: no filename given.");
+ }
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+}
+}
+
+extern "C" {
+
+void init() {
+ Mad::Modules::FileLogger::registerConfigHelper();
+}
+
+void deinit() {
+ Mad::Modules::FileLogger::unregisterConfigHelper();
+}
+
+}
diff --git a/src/modules/FileLogger.h b/src/modules/FileLogger.h
new file mode 100644
index 0000000..2def986
--- /dev/null
+++ b/src/modules/FileLogger.h
@@ -0,0 +1,77 @@
+/*
+ * FileLogger.h
+ *
+ * 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/>.
+ */
+
+#ifndef MAD_MODULES_FILELOGGER_H_
+#define MAD_MODULES_FILELOGGER_H_
+
+#include <Common/ConfigManager.h>
+#include <Common/Configurable.h>
+#include <Common/LogManager.h>
+
+#include <fstream>
+
+namespace Mad {
+namespace Modules {
+
+class FileLogger : private Common::Logger, private Common::RemoteLogger {
+ private:
+ class ConfigHelper : public Common::Configurable {
+ protected:
+ virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool handled);
+
+ public:
+ virtual int getPriority() const {return 1;}
+ };
+
+ static ConfigHelper configHelper;
+ static std::set<FileLogger*> loggers;
+
+ std::ofstream file;
+
+ protected:
+ 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)
+ : file(filename.c_str(), std::ios::out|std::ios::app) {}
+
+ static void registerConfigHelper() {
+ Common::ConfigManager::get()->registerConfigurable(&configHelper);
+ }
+
+ static void unregisterConfigHelper() {
+ Common::ConfigManager::get()->unregisterConfigurable(&configHelper);
+
+ for(std::set<FileLogger*>::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
+ delete *logger;
+ }
+
+ loggers.clear();
+ }
+};
+
+}
+}
+
+#endif /* MAD_MODULES_FILELOGGER_H_ */
diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am
index 5e12a5d..67a82b8 100644
--- a/src/modules/Makefile.am
+++ b/src/modules/Makefile.am
@@ -1,12 +1,12 @@
-madlibdir = ${libdir}/mad
-moddir = ${madlibdir}/modules
+moddir = ${pkglibdir}/modules
default_ldflags = -module -avoid-version -export-dynamic
+static_ldflags = $(default_ldflags) -static -rpath $(moddir)
EXTRA_LTLIBTRARIES = SystemBackendPosix.la SystemBackendProc.la UserBackendMysql.la
-mod_LTLIBRARIES =
-noinst_LTLIBRARIES =
+mod_LTLIBRARIES =
+noinst_LTLIBRARIES = FileLogger.la
if SYSTEMBACKEND_POSIX
noinst_LTLIBRARIES += SystemBackendPosix.la
@@ -20,12 +20,15 @@ if USERBACKEND_MYSQL
mod_LTLIBRARIES += UserBackendMysql.la
endif
+FileLogger_la_SOURCES = FileLogger.cpp
+FileLogger_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^FileLogger_LTX_'
+
SystemBackendPosix_la_SOURCES = SystemBackendPosix.cpp
SystemBackendPosix_la_LIBADD = $(sigc_LIBS)
-SystemBackendPosix_la_LDFLAGS = $(default_ldflags) -static -export-symbols-regex '^SystemBackendPosix_LTX_'
+SystemBackendPosix_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendPosix_LTX_'
SystemBackendProc_la_SOURCES = SystemBackendProc.cpp
-SystemBackendProc_la_LDFLAGS = $(default_ldflags) -static -export-symbols-regex '^SystemBackendProc_LTX_'
+SystemBackendProc_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendProc_LTX_'
UserBackendMysql_la_SOURCES = UserBackendMysql.cpp
UserBackendMysql_la_LIBADD = $(MYSQL_LDFLAGS)
diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in
index 59909ee..f396b8d 100644
--- a/src/modules/Makefile.in
+++ b/src/modules/Makefile.in
@@ -60,6 +60,12 @@ am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(moddir)"
modLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(mod_LTLIBRARIES) $(noinst_LTLIBRARIES)
+FileLogger_la_LIBADD =
+am_FileLogger_la_OBJECTS = FileLogger.lo
+FileLogger_la_OBJECTS = $(am_FileLogger_la_OBJECTS)
+FileLogger_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(FileLogger_la_LDFLAGS) $(LDFLAGS) -o $@
am__DEPENDENCIES_1 =
SystemBackendPosix_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_SystemBackendPosix_la_OBJECTS = SystemBackendPosix.lo
@@ -95,9 +101,10 @@ CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
-SOURCES = $(SystemBackendPosix_la_SOURCES) \
+SOURCES = $(FileLogger_la_SOURCES) $(SystemBackendPosix_la_SOURCES) \
$(SystemBackendProc_la_SOURCES) $(UserBackendMysql_la_SOURCES)
-DIST_SOURCES = $(SystemBackendPosix_la_SOURCES) \
+DIST_SOURCES = $(FileLogger_la_SOURCES) \
+ $(SystemBackendPosix_la_SOURCES) \
$(SystemBackendProc_la_SOURCES) $(UserBackendMysql_la_SOURCES)
HEADERS = $(noinst_HEADERS)
ETAGS = etags
@@ -245,17 +252,19 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-madlibdir = ${libdir}/mad
-moddir = ${madlibdir}/modules
+moddir = ${pkglibdir}/modules
default_ldflags = -module -avoid-version -export-dynamic
+static_ldflags = $(default_ldflags) -static -rpath $(moddir)
EXTRA_LTLIBTRARIES = SystemBackendPosix.la SystemBackendProc.la UserBackendMysql.la
mod_LTLIBRARIES = $(am__append_3)
-noinst_LTLIBRARIES = $(am__append_1) $(am__append_2)
+noinst_LTLIBRARIES = FileLogger.la $(am__append_1) $(am__append_2)
+FileLogger_la_SOURCES = FileLogger.cpp
+FileLogger_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^FileLogger_LTX_'
SystemBackendPosix_la_SOURCES = SystemBackendPosix.cpp
SystemBackendPosix_la_LIBADD = $(sigc_LIBS)
-SystemBackendPosix_la_LDFLAGS = $(default_ldflags) -static -export-symbols-regex '^SystemBackendPosix_LTX_'
+SystemBackendPosix_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendPosix_LTX_'
SystemBackendProc_la_SOURCES = SystemBackendProc.cpp
-SystemBackendProc_la_LDFLAGS = $(default_ldflags) -static -export-symbols-regex '^SystemBackendProc_LTX_'
+SystemBackendProc_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemBackendProc_LTX_'
UserBackendMysql_la_SOURCES = UserBackendMysql.cpp
UserBackendMysql_la_LIBADD = $(MYSQL_LDFLAGS)
UserBackendMysql_la_LDFLAGS = $(default_ldflags) -export-symbols-regex '^UserBackendMysql_LTX_'
@@ -329,6 +338,8 @@ clean-noinstLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
+FileLogger.la: $(FileLogger_la_OBJECTS) $(FileLogger_la_DEPENDENCIES)
+ $(FileLogger_la_LINK) $(FileLogger_la_OBJECTS) $(FileLogger_la_LIBADD) $(LIBS)
SystemBackendPosix.la: $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_DEPENDENCIES)
$(SystemBackendPosix_la_LINK) $(am_SystemBackendPosix_la_rpath) $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_LIBADD) $(LIBS)
SystemBackendProc.la: $(SystemBackendProc_la_OBJECTS) $(SystemBackendProc_la_DEPENDENCIES)
@@ -342,6 +353,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileLogger.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendPosix.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackendProc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserBackendMysql.Plo@am__quote@