aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael 'Mickey' Lauer <mickey@vanille-media.de>2009-03-01 16:44:06 +0100
committerMichael 'Mickey' Lauer <mickey@vanille-media.de>2009-03-01 16:44:06 +0100
commita2131fc4e6cce53e3230de4e87215a847fafe078 (patch)
tree5052165e4f444aa61a63a8fb1e61ce4d5c4f7b18
parentedb406cc5fe0425c196704558382527251e08dfd (diff)
downloadcornucopia-a2131fc4e6cce53e3230de4e87215a847fafe078.tar.gz
cornucopia-a2131fc4e6cce53e3230de4e87215a847fafe078.tar.bz2
cornucopia-a2131fc4e6cce53e3230de4e87215a847fafe078.zip
start with logging class
-rw-r--r--.gitignore27
-rw-r--r--libfsoframework/README6
-rw-r--r--libfsoframework/configure.ac3
-rw-r--r--libfsoframework/fsoframework/Makefile.am2
-rw-r--r--libfsoframework/fsoframework/fsoframework-2.0.gir140
-rw-r--r--libfsoframework/fsoframework/fsoframework-2.0.vapi19
-rw-r--r--libfsoframework/fsoframework/logger.c217
-rw-r--r--libfsoframework/fsoframework/logger.h85
-rw-r--r--libfsoframework/fsoframework/logger.vala102
-rw-r--r--libfsoframework/tests/.gitignore1
-rw-r--r--libfsoframework/tests/Makefile.am8
-rw-r--r--libfsoframework/tests/testlogger.vala57
12 files changed, 664 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..38a586be
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+Makefile.in
+Makefile
+*.o
+*.lo
+*.la
+*.c
+*.h
+*.stamp
+*.gir
+.deps
+.libs
+
+config.*
+aclocal.m4
+autom4te.cache
+ChangeLog
+configure
+depcomp
+libtool
+install-sh
+missing
+ltmain.sh
+ylwrap
+compile
+stamp-h1
+*.pc
+
diff --git a/libfsoframework/README b/libfsoframework/README
index 8fbc6000..d57729b4 100644
--- a/libfsoframework/README
+++ b/libfsoframework/README
@@ -1 +1,7 @@
fso framework library
+
+Paradigm: Test Driven Development
+
+Indentation: -bad -bap -bbb -bl -bli0 -bs -cbi4 -cli4 -i4 -l100 -lp
+ -nbbo -nbc -ncs -npcs -npsl -nut
+ -pi0 -prs-saf -sai -saw -sbi4 -st
diff --git a/libfsoframework/configure.ac b/libfsoframework/configure.ac
index 44644e52..716f5c2e 100644
--- a/libfsoframework/configure.ac
+++ b/libfsoframework/configure.ac
@@ -19,7 +19,8 @@ GLIB_REQUIRED=2.18.0
PKG_CHECK_MODULES(DEPS,
glib-2.0 >= $GLIB_REQUIRED
- gobject-2.0 >= $GLIB_REQUIRED)
+ gobject-2.0 >= $GLIB_REQUIRED
+ gio-2.0 >= $GLIB_REQUIRED)
AC_SUBST(DEPS_CFLAGS)
AC_SUBST(DEPS_LIBS)
diff --git a/libfsoframework/fsoframework/Makefile.am b/libfsoframework/fsoframework/Makefile.am
index 464c037e..36ce68e0 100644
--- a/libfsoframework/fsoframework/Makefile.am
+++ b/libfsoframework/fsoframework/Makefile.am
@@ -33,7 +33,9 @@ fsoframeworkinclude_HEADERS = \
fsoframework-1.0.vapi fsoframework.vala.stamp: $(libfsoframework_la_VALASOURCES)
$(VALAC) -C --basedir $(top_srcdir) \
+ --pkg posix \
--pkg glib-2.0 \
+ --pkg gio-2.0 \
--library fsoframework-2.0 $^
touch $@
diff --git a/libfsoframework/fsoframework/fsoframework-2.0.gir b/libfsoframework/fsoframework/fsoframework-2.0.gir
index def87aaf..60f6c29d 100644
--- a/libfsoframework/fsoframework/fsoframework-2.0.gir
+++ b/libfsoframework/fsoframework/fsoframework-2.0.gir
@@ -1,6 +1,146 @@
<?xml version="1.0"?>
<repository version="1.0">
<namespace name="FsoFramework" version="1.0">
+ <class name="AbstractLogger" parent="GLib.Object" glib:type-name="FsoFrameworkAbstractLogger" glib:get-type="fso_framework_abstract_logger_get_type">
+ <field name="level">
+ <type name="uint"/>
+ </field>
+ <field name="domain">
+ <type name="string"/>
+ </field>
+ <field name="destination">
+ <type name="string"/>
+ </field>
+ <method name="write" c:identifier="fso_framework_abstract_logger_write">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="message">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ <constructor name="new" c:identifier="fso_framework_abstract_logger_new">
+ <parameters>
+ <parameter name="domain">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="FsoFramework.AbstractLogger"/>
+ </return-value>
+ </constructor>
+ <method name="setLevel" c:identifier="fso_framework_abstract_logger_setLevel">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="level">
+ <type name="GLib.LogLevelFlags"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="setDestination" c:identifier="fso_framework_abstract_logger_setDestination">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="destination">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="debug" c:identifier="fso_framework_abstract_logger_debug">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="message">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="info" c:identifier="fso_framework_abstract_logger_info">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="message">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="warning" c:identifier="fso_framework_abstract_logger_warning">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="message">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="error" c:identifier="fso_framework_abstract_logger_error">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.AbstractLogger"/>
+ </parameter>
+ <parameter name="message">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ </class>
+ <class name="FileLogger" parent="FsoFramework.AbstractLogger" glib:type-name="FsoFrameworkFileLogger" glib:get-type="fso_framework_file_logger_get_type">
+ <constructor name="new" c:identifier="fso_framework_file_logger_new">
+ <parameters>
+ <parameter name="domain">
+ <type name="string"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="FsoFramework.FileLogger"/>
+ </return-value>
+ </constructor>
+ <method name="setFile" c:identifier="fso_framework_file_logger_setFile">
+ <parameters>
+ <parameter name="self">
+ <type name="FsoFramework.FileLogger"/>
+ </parameter>
+ <parameter name="filename">
+ <type name="string"/>
+ </parameter>
+ <parameter name="append">
+ <type name="bool"/>
+ </parameter>
+ </parameters>
+ <return-value>
+ <type name="none"/>
+ </return-value>
+ </method>
+ </class>
<class name="SmartKeyFile" parent="GLib.Object" glib:type-name="FsoFrameworkSmartKeyFile" glib:get-type="fso_framework_smart_key_file_get_type">
<method name="loadFromFile" c:identifier="fso_framework_smart_key_file_loadFromFile">
<parameters>
diff --git a/libfsoframework/fsoframework/fsoframework-2.0.vapi b/libfsoframework/fsoframework/fsoframework-2.0.vapi
index a0c7671f..14401d9e 100644
--- a/libfsoframework/fsoframework/fsoframework-2.0.vapi
+++ b/libfsoframework/fsoframework/fsoframework-2.0.vapi
@@ -2,6 +2,25 @@
[CCode (cprefix = "FsoFramework", lower_case_cprefix = "fso_framework_")]
namespace FsoFramework {
+ [CCode (cheader_filename = "fsoframework/logger.h")]
+ public abstract class AbstractLogger : GLib.Object {
+ protected string destination;
+ protected string domain;
+ protected uint level;
+ public void debug (string message);
+ public void error (string message);
+ public void info (string message);
+ public AbstractLogger (string domain);
+ public void setDestination (string destination);
+ public void setLevel (GLib.LogLevelFlags level);
+ public void warning (string message);
+ protected virtual void write (string message);
+ }
+ [CCode (cheader_filename = "fsoframework/logger.h")]
+ public class FileLogger : FsoFramework.AbstractLogger {
+ public FileLogger (string domain);
+ public void setFile (string filename, bool append = false);
+ }
[CCode (cheader_filename = "fsoframework/smartkeyfile.h")]
public class SmartKeyFile : GLib.Object {
public bool boolValue (string section, string key, bool defaultvalue);
diff --git a/libfsoframework/fsoframework/logger.c b/libfsoframework/fsoframework/logger.c
index d269a073..74871ec8 100644
--- a/libfsoframework/fsoframework/logger.c
+++ b/libfsoframework/fsoframework/logger.c
@@ -1,10 +1,227 @@
+/**
+ * Copyright (C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
#include <fsoframework/logger.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+
+
+
+enum {
+ FSO_FRAMEWORK_ABSTRACT_LOGGER_DUMMY_PROPERTY
+};
+static void fso_framework_abstract_logger_real_write (FsoFrameworkAbstractLogger* self, const char* message);
+static gpointer fso_framework_abstract_logger_parent_class = NULL;
+static void fso_framework_abstract_logger_finalize (GObject* obj);
+struct _FsoFrameworkFileLoggerPrivate {
+ gint file;
+};
+
+#define FSO_FRAMEWORK_FILE_LOGGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FSO_FRAMEWORK_TYPE_FILE_LOGGER, FsoFrameworkFileLoggerPrivate))
+enum {
+ FSO_FRAMEWORK_FILE_LOGGER_DUMMY_PROPERTY
+};
+static gpointer fso_framework_file_logger_parent_class = NULL;
+static void fso_framework_file_logger_finalize (GObject* obj);
+
+
+
+static void fso_framework_abstract_logger_real_write (FsoFrameworkAbstractLogger* self, const char* message) {
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (message != NULL);
+}
+
+
+void fso_framework_abstract_logger_write (FsoFrameworkAbstractLogger* self, const char* message) {
+ FSO_FRAMEWORK_ABSTRACT_LOGGER_GET_CLASS (self)->write (self, message);
+}
+
+
+FsoFrameworkAbstractLogger* fso_framework_abstract_logger_construct (GType object_type, const char* domain) {
+ FsoFrameworkAbstractLogger * self;
+ char* _tmp1;
+ const char* _tmp0;
+ g_return_val_if_fail (domain != NULL, NULL);
+ self = g_object_newv (object_type, 0, NULL);
+ _tmp1 = NULL;
+ _tmp0 = NULL;
+ self->domain = (_tmp1 = (_tmp0 = domain, (_tmp0 == NULL) ? NULL : g_strdup (_tmp0)), self->domain = (g_free (self->domain), NULL), _tmp1);
+ return self;
+}
+
+
+FsoFrameworkAbstractLogger* fso_framework_abstract_logger_new (const char* domain) {
+ return fso_framework_abstract_logger_construct (FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER, domain);
+}
+
+
+void fso_framework_abstract_logger_setLevel (FsoFrameworkAbstractLogger* self, GLogLevelFlags level) {
+ g_return_if_fail (self != NULL);
+ self->level = (guint) level;
+}
+
+
+void fso_framework_abstract_logger_setDestination (FsoFrameworkAbstractLogger* self, const char* destination) {
+ char* _tmp1;
+ const char* _tmp0;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (destination != NULL);
+ _tmp1 = NULL;
+ _tmp0 = NULL;
+ self->destination = (_tmp1 = (_tmp0 = destination, (_tmp0 == NULL) ? NULL : g_strdup (_tmp0)), self->destination = (g_free (self->destination), NULL), _tmp1);
+}
+
+
+void fso_framework_abstract_logger_debug (FsoFrameworkAbstractLogger* self, const char* message) {
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (message != NULL);
+ if (self->level >= ((guint) G_LOG_LEVEL_DEBUG)) {
+ fso_framework_abstract_logger_write (self, message);
+ }
+}
+
+
+void fso_framework_abstract_logger_info (FsoFrameworkAbstractLogger* self, const char* message) {
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (message != NULL);
+ if (self->level >= ((guint) G_LOG_LEVEL_INFO)) {
+ fso_framework_abstract_logger_write (self, message);
+ }
+}
+
+
+void fso_framework_abstract_logger_warning (FsoFrameworkAbstractLogger* self, const char* message) {
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (message != NULL);
+ if (self->level >= ((guint) G_LOG_LEVEL_WARNING)) {
+ fso_framework_abstract_logger_write (self, message);
+ }
+}
+
+
+void fso_framework_abstract_logger_error (FsoFrameworkAbstractLogger* self, const char* message) {
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (message != NULL);
+ if (self->level >= ((guint) G_LOG_LEVEL_ERROR)) {
+ fso_framework_abstract_logger_write (self, message);
+ }
+}
+
+
+static void fso_framework_abstract_logger_class_init (FsoFrameworkAbstractLoggerClass * klass) {
+ fso_framework_abstract_logger_parent_class = g_type_class_peek_parent (klass);
+ G_OBJECT_CLASS (klass)->finalize = fso_framework_abstract_logger_finalize;
+ FSO_FRAMEWORK_ABSTRACT_LOGGER_CLASS (klass)->write = fso_framework_abstract_logger_real_write;
+}
+
+
+static void fso_framework_abstract_logger_instance_init (FsoFrameworkAbstractLogger * self) {
+ self->level = (guint) G_LOG_LEVEL_INFO;
+}
+
+
+static void fso_framework_abstract_logger_finalize (GObject* obj) {
+ FsoFrameworkAbstractLogger * self;
+ self = FSO_FRAMEWORK_ABSTRACT_LOGGER (obj);
+ self->domain = (g_free (self->domain), NULL);
+ self->destination = (g_free (self->destination), NULL);
+ G_OBJECT_CLASS (fso_framework_abstract_logger_parent_class)->finalize (obj);
+}
+
+
+GType fso_framework_abstract_logger_get_type (void) {
+ static GType fso_framework_abstract_logger_type_id = 0;
+ if (fso_framework_abstract_logger_type_id == 0) {
+ static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkAbstractLoggerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_framework_abstract_logger_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoFrameworkAbstractLogger), 0, (GInstanceInitFunc) fso_framework_abstract_logger_instance_init, NULL };
+ fso_framework_abstract_logger_type_id = g_type_register_static (G_TYPE_OBJECT, "FsoFrameworkAbstractLogger", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
+ }
+ return fso_framework_abstract_logger_type_id;
+}
+
+
+FsoFrameworkFileLogger* fso_framework_file_logger_construct (GType object_type, const char* domain) {
+ FsoFrameworkFileLogger * self;
+ g_return_val_if_fail (domain != NULL, NULL);
+ self = (FsoFrameworkFileLogger*) fso_framework_abstract_logger_construct (object_type, domain);
+ return self;
+}
+
+
+FsoFrameworkFileLogger* fso_framework_file_logger_new (const char* domain) {
+ return fso_framework_file_logger_construct (FSO_FRAMEWORK_TYPE_FILE_LOGGER, domain);
+}
+
+
+void fso_framework_file_logger_setFile (FsoFrameworkFileLogger* self, const char* filename, gboolean append) {
+ gint flags;
+ char* _tmp2;
+ const char* _tmp1;
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (filename != NULL);
+ if (self->priv->file != (-1)) {
+ char* _tmp0;
+ _tmp0 = NULL;
+ ((FsoFrameworkAbstractLogger*) self)->destination = (_tmp0 = NULL, ((FsoFrameworkAbstractLogger*) self)->destination = (g_free (((FsoFrameworkAbstractLogger*) self)->destination), NULL), _tmp0);
+ close (self->priv->file);
+ }
+ flags = (O_EXCL | O_CREAT) | O_WRONLY;
+ if (append) {
+ flags = flags | O_APPEND;
+ }
+ self->priv->file = open (filename, flags, S_IRWXU);
+ _tmp2 = NULL;
+ _tmp1 = NULL;
+ ((FsoFrameworkAbstractLogger*) self)->destination = (_tmp2 = (_tmp1 = filename, (_tmp1 == NULL) ? NULL : g_strdup (_tmp1)), ((FsoFrameworkAbstractLogger*) self)->destination = (g_free (((FsoFrameworkAbstractLogger*) self)->destination), NULL), _tmp2);
+}
+
+
+static void fso_framework_file_logger_class_init (FsoFrameworkFileLoggerClass * klass) {
+ fso_framework_file_logger_parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (klass, sizeof (FsoFrameworkFileLoggerPrivate));
+ G_OBJECT_CLASS (klass)->finalize = fso_framework_file_logger_finalize;
+}
+
+static void fso_framework_file_logger_instance_init (FsoFrameworkFileLogger * self) {
+ self->priv = FSO_FRAMEWORK_FILE_LOGGER_GET_PRIVATE (self);
+ self->priv->file = -1;
+}
+static void fso_framework_file_logger_finalize (GObject* obj) {
+ FsoFrameworkFileLogger * self;
+ self = FSO_FRAMEWORK_FILE_LOGGER (obj);
+ G_OBJECT_CLASS (fso_framework_file_logger_parent_class)->finalize (obj);
+}
+GType fso_framework_file_logger_get_type (void) {
+ static GType fso_framework_file_logger_type_id = 0;
+ if (fso_framework_file_logger_type_id == 0) {
+ static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkFileLoggerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_framework_file_logger_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoFrameworkFileLogger), 0, (GInstanceInitFunc) fso_framework_file_logger_instance_init, NULL };
+ fso_framework_file_logger_type_id = g_type_register_static (FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER, "FsoFrameworkFileLogger", &g_define_type_info, 0);
+ }
+ return fso_framework_file_logger_type_id;
+}
diff --git a/libfsoframework/fsoframework/logger.h b/libfsoframework/fsoframework/logger.h
index 352f61fc..2abb0e3e 100644
--- a/libfsoframework/fsoframework/logger.h
+++ b/libfsoframework/fsoframework/logger.h
@@ -1,15 +1,98 @@
+/**
+ * Copyright (C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
#ifndef __FSOFRAMEWORK_LOGGER_H__
#define __FSOFRAMEWORK_LOGGER_H__
#include <glib.h>
#include <glib-object.h>
+#include <stdlib.h>
+#include <string.h>
G_BEGIN_DECLS
+#define FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER (fso_framework_abstract_logger_get_type ())
+#define FSO_FRAMEWORK_ABSTRACT_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER, FsoFrameworkAbstractLogger))
+#define FSO_FRAMEWORK_ABSTRACT_LOGGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER, FsoFrameworkAbstractLoggerClass))
+#define FSO_FRAMEWORK_IS_ABSTRACT_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER))
+#define FSO_FRAMEWORK_IS_ABSTRACT_LOGGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER))
+#define FSO_FRAMEWORK_ABSTRACT_LOGGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_FRAMEWORK_TYPE_ABSTRACT_LOGGER, FsoFrameworkAbstractLoggerClass))
+
+typedef struct _FsoFrameworkAbstractLogger FsoFrameworkAbstractLogger;
+typedef struct _FsoFrameworkAbstractLoggerClass FsoFrameworkAbstractLoggerClass;
+typedef struct _FsoFrameworkAbstractLoggerPrivate FsoFrameworkAbstractLoggerPrivate;
+
+#define FSO_FRAMEWORK_TYPE_FILE_LOGGER (fso_framework_file_logger_get_type ())
+#define FSO_FRAMEWORK_FILE_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_FILE_LOGGER, FsoFrameworkFileLogger))
+#define FSO_FRAMEWORK_FILE_LOGGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_FRAMEWORK_TYPE_FILE_LOGGER, FsoFrameworkFileLoggerClass))
+#define FSO_FRAMEWORK_IS_FILE_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_FILE_LOGGER))
+#define FSO_FRAMEWORK_IS_FILE_LOGGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_FRAMEWORK_TYPE_FILE_LOGGER))
+#define FSO_FRAMEWORK_FILE_LOGGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_FRAMEWORK_TYPE_FILE_LOGGER, FsoFrameworkFileLoggerClass))
+
+typedef struct _FsoFrameworkFileLogger FsoFrameworkFileLogger;
+typedef struct _FsoFrameworkFileLoggerClass FsoFrameworkFileLoggerClass;
+typedef struct _FsoFrameworkFileLoggerPrivate FsoFrameworkFileLoggerPrivate;
+
+/**
+ * AbstractLogger
+ */
+struct _FsoFrameworkAbstractLogger {
+ GObject parent_instance;
+ FsoFrameworkAbstractLoggerPrivate * priv;
+ guint level;
+ char* domain;
+ char* destination;
+};
+
+struct _FsoFrameworkAbstractLoggerClass {
+ GObjectClass parent_class;
+ void (*write) (FsoFrameworkAbstractLogger* self, const char* message);
+};
+
+/**
+ * FileLogger
+ */
+struct _FsoFrameworkFileLogger {
+ FsoFrameworkAbstractLogger parent_instance;
+ FsoFrameworkFileLoggerPrivate * priv;
+};
+
+struct _FsoFrameworkFileLoggerClass {
+ FsoFrameworkAbstractLoggerClass parent_class;
+};
+
-#define foo (gint) "10"
+void fso_framework_abstract_logger_write (FsoFrameworkAbstractLogger* self, const char* message);
+FsoFrameworkAbstractLogger* fso_framework_abstract_logger_construct (GType object_type, const char* domain);
+FsoFrameworkAbstractLogger* fso_framework_abstract_logger_new (const char* domain);
+void fso_framework_abstract_logger_setLevel (FsoFrameworkAbstractLogger* self, GLogLevelFlags level);
+void fso_framework_abstract_logger_setDestination (FsoFrameworkAbstractLogger* self, const char* destination);
+void fso_framework_abstract_logger_debug (FsoFrameworkAbstractLogger* self, const char* message);
+void fso_framework_abstract_logger_info (FsoFrameworkAbstractLogger* self, const char* message);
+void fso_framework_abstract_logger_warning (FsoFrameworkAbstractLogger* self, const char* message);
+void fso_framework_abstract_logger_error (FsoFrameworkAbstractLogger* self, const char* message);
+GType fso_framework_abstract_logger_get_type (void);
+FsoFrameworkFileLogger* fso_framework_file_logger_construct (GType object_type, const char* domain);
+FsoFrameworkFileLogger* fso_framework_file_logger_new (const char* domain);
+void fso_framework_file_logger_setFile (FsoFrameworkFileLogger* self, const char* filename, gboolean append);
+GType fso_framework_file_logger_get_type (void);
G_END_DECLS
diff --git a/libfsoframework/fsoframework/logger.vala b/libfsoframework/fsoframework/logger.vala
index f67ca6e1..967daf6c 100644
--- a/libfsoframework/fsoframework/logger.vala
+++ b/libfsoframework/fsoframework/logger.vala
@@ -1,3 +1,103 @@
+/**
+ * Copyright (C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
using GLib;
-const int foo = "10"; \ No newline at end of file
+/**
+ * AbstractLogger
+ */
+public abstract class FsoFramework.AbstractLogger : Object
+{
+ protected uint level = LogLevelFlags.LEVEL_INFO;
+ protected string domain;
+ protected string destination;
+
+ protected virtual void write( string message )
+ {
+ }
+
+ public AbstractLogger( string domain )
+ {
+ this.domain = domain;
+ }
+
+ public void setLevel( LogLevelFlags level )
+ {
+ this.level = (uint)level;
+ }
+
+ public void setDestination( string destination )
+ {
+ this.destination = destination;
+ }
+
+ public void debug( string message )
+ {
+ if ( level >= (uint)LogLevelFlags.LEVEL_DEBUG )
+ write( message );
+ }
+
+ public void info( string message )
+ {
+ if ( level >= (uint)LogLevelFlags.LEVEL_INFO )
+ write( message );
+ }
+
+ public void warning( string message )
+ {
+ if ( level >= (uint)LogLevelFlags.LEVEL_WARNING )
+ write( message );
+ }
+
+ public void error( string message )
+ {
+ if ( level >= (uint)LogLevelFlags.LEVEL_ERROR )
+ write( message );
+ }
+}
+
+/**
+ * FileLogger
+ */
+public class FsoFramework.FileLogger : FsoFramework.AbstractLogger
+{
+ int file = -1;
+
+ public FileLogger( string domain )
+ {
+ base( domain );
+ }
+
+ public void setFile( string filename, bool append = false )
+ {
+ if ( file != -1 )
+ {
+ this.destination = null;
+ Posix.close( file );
+ }
+
+ int flags = Posix.O_EXCL | Posix.O_CREAT | Posix.O_WRONLY;
+ if ( append )
+ flags |= Posix.O_APPEND;
+ file = Posix.open( filename, flags, Posix.S_IRWXU );
+
+ this.destination = filename;
+ }
+
+}
diff --git a/libfsoframework/tests/.gitignore b/libfsoframework/tests/.gitignore
index 4b107cf1..4c774cf2 100644
--- a/libfsoframework/tests/.gitignore
+++ b/libfsoframework/tests/.gitignore
@@ -1,2 +1,3 @@
testsmartkeyfile
+testlogger
diff --git a/libfsoframework/tests/Makefile.am b/libfsoframework/tests/Makefile.am
index e7117f71..1a6da61e 100644
--- a/libfsoframework/tests/Makefile.am
+++ b/libfsoframework/tests/Makefile.am
@@ -20,6 +20,14 @@ $(testsmartkeyfile_SOURCES): $(testsmartkeyfile_VALASOURCES)
testsmartkeyfile_LDADD = $(progs_ldadd)
EXTRA_DIST += $(testsmartkeyfile_VALASOURCES)
+TEST_PROGS += testlogger
+testlogger_VALASOURCES = testlogger.vala
+testlogger_SOURCES = testlogger.c testlogger.h
+$(testlogger_SOURCES): $(testlogger_VALASOURCES)
+ $(VALAC) -C --basedir $(top_srcdir) --vapidir $(top_srcdir)/fsoframework --pkg fsoframework-2.0 $^
+ touch $@
+testlogger_LDADD = $(progs_ldadd)
+EXTRA_DIST += $(testlogger_VALASOURCES)
# TEST_PROGS += testarraylist
# testarraylist_VALASOURCES = testarraylist.vala
diff --git a/libfsoframework/tests/testlogger.vala b/libfsoframework/tests/testlogger.vala
new file mode 100644
index 00000000..8af640c2
--- /dev/null
+++ b/libfsoframework/tests/testlogger.vala
@@ -0,0 +1,57 @@
+/**
+ * Copyright (C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+using GLib;
+using FsoFramework;
+
+const string TEST_FILE_NAME = "/tmp/logfile.txt";
+const string TEST_LOG_DOMAIN = "my.logging.domain";
+
+//===========================================================================
+void test_file_logger_new()
+//===========================================================================
+{
+ FileUtils.remove( TEST_FILE_NAME );
+
+ var logger = new FileLogger( TEST_LOG_DOMAIN );
+ logger.setFile( TEST_FILE_NAME, true );
+
+ logger.debug( "foo" );
+
+ var file = File.new_for_path( TEST_FILE_NAME );
+
+ assert( file.query_exists( null ) );
+
+ var stream = new DataInputStream( file.read( null ) );
+ var firstline = stream.read_line( null, null );
+
+ assert ( "foo" in firstline );
+}
+
+//===========================================================================
+void main (string[] args)
+//===========================================================================
+{
+ Test.init (ref args);
+
+ Test.add_func ("/FileLogger/new", test_file_logger_new);
+ //Test.add_func ("/FileLogger/append", test_file_logger_append);
+
+ Test.run ();
+}