diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2010-02-11 18:08:12 +1100 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2010-02-12 21:45:27 +1100 |
commit | a069bd9707e689724e5a1937d78045d6e5269537 (patch) | |
tree | 060b7ceaf03ec3b059f8b4ed6d5736bc530600cb /src | |
parent | d135413c2ab965cb76daacf2e5e41571e18bd655 (diff) | |
download | telepathy-logger-a069bd9707e689724e5a1937d78045d6e5269537.tar.gz |
telepathy-logger: Enable debugging
Diffstat (limited to 'src')
-rw-r--r-- | src/telepathy-logger.c | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/src/telepathy-logger.c b/src/telepathy-logger.c index 849e63c..8a6f76f 100644 --- a/src/telepathy-logger.c +++ b/src/telepathy-logger.c @@ -19,17 +19,76 @@ * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> */ +#include <config.h> #include <glib.h> -#include <telepathy-glib/dbus.h> +#include <telepathy-glib/telepathy-glib.h> +#include <telepathy-glib/debug-sender.h> #include <telepathy-logger/channel-factory.h> #include <telepathy-logger/channel-text.h> #include <telepathy-logger/observer.h> #include <telepathy-logger/dbus-service.h> +#define DEBUG_FLAG TPL_DEBUG_MAIN +#include <telepathy-logger/debug.h> + static GMainLoop *loop = NULL; +#define ENABLE_DEBUG /* FIXME: make this a configure option */ + +#ifdef ENABLE_DEBUG +static TpDebugSender *debug_sender = NULL; +static gboolean stamp_logs = FALSE; + +static void +log_to_debug_sender (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *string) +{ + GTimeVal now; + + g_return_if_fail (TP_IS_DEBUG_SENDER (debug_sender)); + + g_get_current_time (&now); + + tp_debug_sender_add_message (debug_sender, &now, log_domain, log_level, + string); +} + +static void +log_handler (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) +{ + if (stamp_logs) + { + GTimeVal now; + gchar now_str[32]; + gchar *tmp; + struct tm tm; + + g_get_current_time (&now); + localtime_r (&(now.tv_sec), &tm); + strftime (now_str, 32, "%Y-%m-%d %H:%M:%S", &tm); + tmp = g_strdup_printf ("%s.%06ld: %s", + now_str, now.tv_usec, message); + + g_log_default_handler (log_domain, log_level, tmp, NULL); + + g_free (tmp); + } + else + { + g_log_default_handler (log_domain, log_level, message, NULL); + } + + /* messages are already sent to the debug sender in gabble_debug. */ + if (log_level != G_LOG_LEVEL_DEBUG || tp_strdiff (log_domain, G_LOG_DOMAIN)) + log_to_debug_sender (log_domain, log_level, message); +} +#endif /* ENABLE_DEBUG */ static void telepathy_logger_dbus_init (void) @@ -68,6 +127,18 @@ main (int argc, GError *error = NULL; g_type_init (); + + tp_debug_divert_messages (g_getenv ("TPL_LOGFILE")); + +#ifdef ENABLE_DEBUG + tpl_debug_set_flags_from_env (); + + stamp_logs = (g_getenv ("TPL_TIMING") != NULL); + debug_sender = tp_debug_sender_dup (); + + g_log_set_default_handler (log_handler, NULL); +#endif /* ENABLE_DEBUG */ + tpl_channel_factory_init (); g_debug ("Initialising TPL Channel Factory"); @@ -93,5 +164,10 @@ main (int argc, g_object_unref (observer); tpl_channel_factory_deinit (); +#ifdef ENABLE_DEBUG + g_log_set_default_handler (g_log_default_handler, NULL); + g_object_unref (debug_sender); +#endif /* ENABLE_DEBUG */ + return 0; } |