[telepathy-gabble/master] Redirect wocky debug to the debug interface

Sjoerd Simons sjoerd.simons at collabora.co.uk
Sun Sep 20 05:08:09 PDT 2009


---
 src/connection.c |    3 -
 src/gabble.c     |  114 ++++++++++++++++++++---------------------------------
 src/gabble.h     |    6 ---
 3 files changed, 43 insertions(+), 80 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index f02e35b..8b1612a 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -407,9 +407,6 @@ gabble_connection_init (GabbleConnection *self)
   self->priv = priv;
   self->lmconn = lm_connection_new ();
 
-  /* 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 5238ea0..cce1dca 100644
--- a/src/gabble.c
+++ b/src/gabble.c
@@ -26,6 +26,7 @@
 #include <telepathy-glib/debug.h>
 #include <telepathy-glib/run.h>
 #include <wocky/wocky.h>
+#include <wocky/wocky-debug.h>
 
 #include "debug.h"
 #include "debugger.h"
@@ -40,88 +41,59 @@ construct_cm (void)
 
 #ifdef ENABLE_DEBUG
 static void
-log_to_debugger (GTimeVal *timestamp,
-    const gchar *log_domain,
+log_to_debugger (const gchar *log_domain,
     GLogLevelFlags log_level,
     const gchar *string)
 {
   GabbleDebugger *dbg = gabble_debugger_get_singleton ();
+  GTimeVal now;
+
+  g_get_current_time (&now);
 
-  gabble_debugger_add_message (dbg, timestamp, log_domain, log_level, string);
+  gabble_debugger_add_message (dbg, &now, log_domain, log_level, string);
 }
 
-/* Whether LM_DEBUG should be set and messages sent to the debugger. */
-static gboolean enable_lm_debug = TRUE;
+/* Whether we redirect all wocky log message purely to the debugger */
+static gboolean redirect_wocky = FALSE;
+/* Whether to add a timestamp to the output messages */
+static gboolean stamp_logs = FALSE;
 
 static void
-simple_log (const gchar *log_domain,
+log_handler (const gchar *log_domain,
     GLogLevelFlags log_level,
     const gchar *message,
     gpointer user_data)
 {
-  /* Only use the GLib default log handler on non-LM messages as they will
-     completely overwhelm and are not entirely useful most of the time. Still
-     send them to the debugger though. */
-  if (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. */
-  if (log_level != G_LOG_LEVEL_DEBUG
-      || tp_strdiff (log_domain, G_LOG_DOMAIN))
+  if (!redirect_wocky || tp_strdiff (log_domain, "wocky"))
     {
-      GTimeVal now;
-      g_get_current_time (&now);
-      log_to_debugger (&now, log_domain, log_level, message);
-    }
-}
-
-static void
-stamp_log (const gchar *log_domain,
-    GLogLevelFlags log_level,
-    const gchar *message,
-    gpointer user_data)
-{
-  GTimeVal now;
-  gchar now_str[32];
-  gchar *tmp;
-  struct tm tm;
-
-  /* Only use the GLib default log handler on non-LM messages as they will
-     completely overwhelm and are not entirely useful most of the time. Still
-     send them to the debugger though. */
-  if (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);
+      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);
+        }
     }
 
   /* 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);
+  if (log_level != G_LOG_LEVEL_DEBUG || tp_strdiff (log_domain, G_LOG_DOMAIN))
+    log_to_debugger (log_domain, log_level, message);
 }
 
-void
-gabble_lm_debug (void)
-{
-  GLogFunc log_func;
-
-  /* Only override LM's log handler if the user has *not* set LM_DEBUG
-     manually. */
-  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
 
 
@@ -146,15 +118,15 @@ 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);
+  stamp_logs = (g_getenv ("GABBLE_TIMING") != NULL);
+
+  if (g_getenv ("WOCKY_DEBUG") == NULL)
+    {
+      redirect_wocky = TRUE;
+      wocky_debug_set_flags (DEBUG_XMPP | DEBUG_SASL | DEBUG_PORTER);
+    }
 
-  if (g_getenv ("GABBLE_TIMING") != NULL)
-    g_log_set_default_handler (stamp_log, NULL);
-  else
-    g_log_set_default_handler (simple_log, NULL);
+  g_log_set_default_handler (log_handler, NULL);
 
   if (g_getenv ("GABBLE_PERSIST") != NULL)
     tp_debug_set_persistent (TRUE);
diff --git a/src/gabble.h b/src/gabble.h
index 9fd010a..7d7748b 100644
--- a/src/gabble.h
+++ b/src/gabble.h
@@ -27,12 +27,6 @@ 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
-
 /* To be used only by tests */
 void gabble_init (void);
 
-- 
1.5.6.5



More information about the telepathy-commits mailing list