[telepathy-gabble/master] Set LM_DEBUG=net and override the log handler when LM_DEBUG is not set.

Jonny Lamb jonny.lamb at collabora.co.uk
Wed Jul 1 02:54:23 PDT 2009


This way, LM debug messages will be exposed through the Debug
interface when LM_DEBUG is not set (which is the majority of the
time). If LM_DEBUG is set, then it's a fair assumption that gabble is
being started on the command line, and therefore the Debug interface
isn't so important.

LM have some weird specific way of printing out their debugging
messages, so when LM_DEBUG has been set, I think it's appropriate not
to touch this default handler. Ideally, there would be a way to have
multiple handlers for a domain/level.

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 src/connection.c |    4 ++++
 src/gabble.c     |   42 +++++++++++++++++++++++++++++++++++-------
 src/gabble.h     |    6 ++++++
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 18a7d02..02428aa 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "connection.h"
+#include "gabble.h"
 
 #include <string.h>
 
@@ -347,6 +348,9 @@ gabble_connection_init (GabbleConnection *self)
   self->priv = priv;
   self->lmconn = lm_connection_new (NULL);
 
+  /* Override LM domain log handler. */
+  gabble_lm_debug ();
+
   priv->caps_serial = 1;
   priv->port = 5222;
 }
diff --git a/src/gabble.c b/src/gabble.c
index 12676ae..98052f6 100644
--- a/src/gabble.c
+++ b/src/gabble.c
@@ -49,13 +49,17 @@ log_to_debugger (GTimeVal *timestamp,
   gabble_debugger_add_message (dbg, timestamp, log_domain, log_level, string);
 }
 
+static gboolean enable_lm_debug = TRUE;
+
 static void
 simple_log (const gchar *log_domain,
     GLogLevelFlags log_level,
     const gchar *message,
     gpointer user_data)
 {
-  g_log_default_handler (log_domain, log_level, message, NULL);
+  if (!enable_lm_debug ||
+      (enable_lm_debug && tp_strdiff (log_domain, "LM")))
+    g_log_default_handler (log_domain, log_level, message, NULL);
 
   /* G_LOG_DOMAIN = "gabble". No need to send gabble messages to the debugger
    * as they already have in gabble_debug. */
@@ -79,18 +83,37 @@ stamp_log (const gchar *log_domain,
   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);
+  if (!enable_lm_debug ||
+      (enable_lm_debug && tp_strdiff (log_domain, "LM")))
+    {
+      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);
+    }
 
   /* Gabble messages are already sent to the debugger in gabble_debug. */
   if (log_level != G_LOG_LEVEL_DEBUG
       || tp_strdiff (log_domain, G_LOG_DOMAIN))
     log_to_debugger (&now, log_domain, log_level, message);
 }
+
+void
+gabble_lm_debug (void)
+{
+  GLogFunc log_func;
+
+  if (!enable_lm_debug)
+    return;
+
+  log_func = (g_getenv ("GABBLE_TIMING") != NULL) ? stamp_log : simple_log;
+
+  g_log_set_handler ("LM",
+      G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
+      log_func, NULL);
+}
 #endif
 
 int
@@ -102,6 +125,11 @@ gabble_main (int argc,
 #ifdef ENABLE_DEBUG
   gabble_debug_set_flags_from_env ();
 
+  if (g_getenv ("LM_DEBUG") != NULL)
+    enable_lm_debug = FALSE;
+  else
+    g_setenv ("LM_DEBUG", "net", TRUE);
+
   if (g_getenv ("GABBLE_TIMING") != NULL)
     g_log_set_default_handler (stamp_log, NULL);
   else
diff --git a/src/gabble.h b/src/gabble.h
index eb9e247..4a7d57b 100644
--- a/src/gabble.h
+++ b/src/gabble.h
@@ -27,6 +27,12 @@ G_BEGIN_DECLS
 
 int gabble_main (int argc, char **argv);
 
+#ifdef ENABLE_DEBUG
+void gabble_lm_debug (void);
+#else
+#define gabble_lm_debug() G_STMT_START { } G_STMT_END
+#endif
+
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_H__*/
-- 
1.5.6.5




More information about the telepathy-commits mailing list