#endif
#include <stdio.h>
+#include <string.h>
#include "log.h"
gchar *app_name;
gchar *dir;
+
+ GFile *file;
+ GFileOutputStream *stream;
};
G_DEFINE_TYPE (SolipaLog, solipa_log, G_TYPE_OBJECT)
gchar *_app_name;
+ GError *error;
+
g_return_val_if_fail (IS_SOLIPA (solipa), NULL);
g_return_val_if_fail (app_name != NULL, NULL);
return NULL;
}
+ priv->file = g_file_new_for_path (g_build_filename (priv->dir, "log.log"));
+
+ error = NULL;
+ priv->stream = g_file_append_to (priv->file,
+ G_FILE_CREATE_PRIVATE,
+ NULL,
+ &error);
+ if (priv->stream == NULL || error != NULL)
+ {
+ g_warning ("SolipaLog: unable to create log file: %s.",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ g_free (priv->app_name);
+ g_free (priv->dir);
+ return NULL;
+ }
+
return solipa_log;
}
g_log_set_handler (g_strcmp0 (log_domain, "") == 0 ? NULL : log_domain,
G_LOG_LEVEL_MASK,
- solipa_log_handler, NULL);
+ solipa_log_handler,
+ (gpointer)solipalog);
}
void
const gchar *message,
gpointer user_data)
{
- g_printf ("solipa_log: (%d) %s - %s\n", log_level, log_domain, message);
+ GDateTime *gdt;
+ gchar *buf;
+
+ SolipaLog *solipa_log = (SolipaLog *)user_data;
+ SolipaLogPrivate *priv = SOLIPA_LOG_GET_PRIVATE (solipa_log);
+
+ gdt = g_date_time_new_now_local ();
+
+ buf = g_strdup_printf ("%s [%d] %s - %s\n",
+ g_date_time_format (gdt, "%F %T"),
+ log_level, log_domain, message);
+
+ g_output_stream_write (G_OUTPUT_STREAM (priv->stream), buf, strlen (buf), NULL, NULL);
+
+ g_free (buf);
}
#include <solipa.h>
#include <log.h>
+#define G_LOG_DOMAIN "solipa_test_log"
+
int
main (int argc, char **argv)
{
solipalog = solipa_log_new (solipa, "test_log");
- solipa_log_add_logdomains (solipalog, "", "GLib-GObject", "Solipa", NULL);
+ solipa_log_add_logdomains (solipalog, "", "solipa_test_log", "GLib-GObject", "Solipa", NULL);
error = NULL;
connection = gda_connection_open_from_string ("PostgreSQL",
g_object_unref (parser);
g_object_unref (connection);
+ g_object_unref (solipalog);
+ g_object_unref (solipa);
+
return 0;
}