[telepathy-gabble/master] Record log domain and levels and expose them on the Debug interface.
Jonny Lamb
jonny.lamb at collabora.co.uk
Wed Jun 3 06:10:51 PDT 2009
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
src/debugger.c | 44 ++++++++++++++++++++++++++++++++++++++++----
src/debugger.h | 6 ++++++
src/gabble.c | 11 +++++++----
3 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/src/debugger.c b/src/debugger.c
index 31b2ffd..f48a889 100644
--- a/src/debugger.c
+++ b/src/debugger.c
@@ -43,12 +43,43 @@ enum
};
static GabbleDebugMessage *
-debug_message_new (gdouble timestamp, const gchar *string)
+debug_message_new (gdouble timestamp,
+ const gchar *domain,
+ GLogLevelFlags level,
+ const gchar *string)
{
GabbleDebugMessage *msg;
+ GabbleDebugLevel log_level;
+
+ switch (level)
+ {
+ case G_LOG_LEVEL_ERROR:
+ log_level = GABBLE_DEBUG_LEVEL_ERROR;
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ log_level = GABBLE_DEBUG_LEVEL_CRITICAL;
+ break;
+ case G_LOG_LEVEL_WARNING:
+ log_level = GABBLE_DEBUG_LEVEL_WARNING;
+ break;
+ case G_LOG_LEVEL_MESSAGE:
+ log_level = GABBLE_DEBUG_LEVEL_MESSAGE;
+ break;
+ case G_LOG_LEVEL_INFO:
+ log_level = GABBLE_DEBUG_LEVEL_INFO;
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ log_level = GABBLE_DEBUG_LEVEL_DEBUG;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
msg = g_slice_new0 (GabbleDebugMessage);
msg->timestamp = timestamp;
+ msg->domain = g_strdup (domain);
+ msg->level = log_level;
msg->string = g_strdup (string);
return msg;
}
@@ -56,6 +87,7 @@ debug_message_new (gdouble timestamp, const gchar *string)
static void
debug_message_free (GabbleDebugMessage *msg)
{
+ g_free (msg->domain);
g_free (msg->string);
g_slice_free (GabbleDebugMessage, msg);
}
@@ -150,7 +182,7 @@ get_messages (GabbleSvcDebug *self, DBusGMethodInvocation *context)
if (G_UNLIKELY (struct_type == 0))
{
struct_type = dbus_g_type_get_struct (
- "GValueArray", G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_INVALID);
+ "GValueArray", G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID);
}
messages = g_ptr_array_sized_new (g_queue_get_length (dbg->messages));
@@ -165,7 +197,9 @@ get_messages (GabbleSvcDebug *self, DBusGMethodInvocation *context)
dbus_g_type_specialized_construct (struct_type));
dbus_g_type_struct_set (&gvalue,
0, message->timestamp,
- 1, message->string,
+ 1, message->domain,
+ 2, message->level,
+ 3, message->string,
G_MAXUINT);
g_ptr_array_add (messages, g_value_get_boxed (&gvalue));
}
@@ -211,6 +245,8 @@ gabble_debugger_get_singleton (void)
void
gabble_debugger_add_message (GabbleDebugger *self,
gdouble timestamp,
+ const gchar *domain,
+ GLogLevelFlags level,
const gchar *string)
{
GabbleDebugMessage *new_msg;
@@ -223,7 +259,7 @@ gabble_debugger_add_message (GabbleDebugger *self,
debug_message_free (old_head);
}
- new_msg = debug_message_new (timestamp, string);
+ new_msg = debug_message_new (timestamp, domain, level, string);
g_queue_push_tail (self->messages, new_msg);
if (self->enabled)
diff --git a/src/debugger.h b/src/debugger.h
index b10545d..95ce0d7 100644
--- a/src/debugger.h
+++ b/src/debugger.h
@@ -25,6 +25,8 @@
#include <telepathy-glib/properties-mixin.h>
#include <telepathy-glib/dbus-properties-mixin.h>
+#include "extensions/extensions.h"
+
G_BEGIN_DECLS
#define GABBLE_TYPE_DEBUGGER gabble_debugger_get_type()
@@ -52,6 +54,8 @@ G_BEGIN_DECLS
typedef struct {
gdouble timestamp;
+ gchar *domain;
+ GabbleDebugLevel level;
gchar *string;
} GabbleDebugMessage;
@@ -75,6 +79,8 @@ gabble_debugger_get_singleton (void);
void
gabble_debugger_add_message (GabbleDebugger *self,
gdouble timestamp,
+ const gchar *domain,
+ GLogLevelFlags level,
const gchar *string);
G_END_DECLS
diff --git a/src/gabble.c b/src/gabble.c
index 9f49778..72cabf9 100644
--- a/src/gabble.c
+++ b/src/gabble.c
@@ -39,12 +39,15 @@ construct_cm (void)
#ifdef ENABLE_DEBUG
static void
-log_to_debugger (GTimeVal *timestamp, const gchar *string)
+log_to_debugger (GTimeVal *timestamp,
+ const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *string)
{
GabbleDebugger *dbg = gabble_debugger_get_singleton ();
gdouble seconds = timestamp->tv_sec + timestamp->tv_usec / 1e6;
- gabble_debugger_add_message (dbg, seconds, string);
+ gabble_debugger_add_message (dbg, seconds, log_domain, log_level, string);
}
static void
@@ -57,7 +60,7 @@ simple_log (const gchar *log_domain,
g_log_default_handler (log_domain, log_level, message, NULL);
g_get_current_time (&now);
- log_to_debugger (&now, message);
+ log_to_debugger (&now, log_domain, log_level, message);
}
static void
@@ -77,7 +80,7 @@ stamp_log (const gchar *log_domain,
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);
- log_to_debugger (&now, message);
+ log_to_debugger (&now, log_domain, log_level, message);
}
#endif
--
1.5.6.5
More information about the telepathy-commits
mailing list