Index: gobject/gobjectmodule.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygobject/gobject/gobjectmodule.c,v
retrieving revision 1.218
diff -u -p -r1.218 gobjectmodule.c
--- gobject/gobjectmodule.c	1 May 2006 16:11:52 -0000	1.218
+++ gobject/gobjectmodule.c	6 May 2006 17:51:18 -0000
@@ -31,6 +31,8 @@
 static PyObject *gerror_exc = NULL;
 static gboolean use_gil_state_api = FALSE;
 static PyObject *_pyg_signal_accumulator_true_handled_func;
+static GHashTable *log_handlers;
+static gboolean log_handlers_disabled;

 GQuark pyginterface_type_key;
 GQuark pygobject_class_init_key;
@@ -3018,6 +3020,50 @@ _log_func(const gchar *log_domain,
     pyg_gil_state_release(state);
 }

+static void
+set_log_handler(const char *domain,
+	        PyObject   *warning)
+{
+    g_return_if_fail (domain != NULL);
+    g_return_if_fail (warning != NULL);
+
+    if (!log_handlers_disabled)
+    {
+	guint handler;
+	gpointer old_handler;
+
+	if (!log_handlers)
+	    log_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+	if ((old_handler = g_hash_table_lookup(log_handlers, domain)))
+	    g_log_remove_handler(domain, GPOINTER_TO_UINT(old_handler));
+
+	handler = g_log_set_handler(domain, G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
+	                            _log_func, warning);
+	g_hash_table_insert(log_handlers, g_strdup (domain), GUINT_TO_POINTER (handler));
+    }
+}
+
+static void
+remove_handler(const char *domain,
+               gpointer	   handler)
+{
+    g_log_remove_handler(domain, GPOINTER_TO_UINT(handler));
+}
+
+static void
+disable_log_handlers(void)
+{
+    log_handlers_disabled = TRUE;
+
+    if (log_handlers)
+    {
+	g_hash_table_foreach(log_handlers, remove_handler, NULL);
+	g_hash_table_destroy(log_handlers);
+	log_handlers = NULL;
+    }
+}
+
 /* ----------------- gobject module initialisation -------------- */

 struct _PyGObject_Functions pygobject_api_functions = {
@@ -3087,7 +3133,10 @@ struct _PyGObject_Functions pygobject_ap
   pyg_closure_set_exception_handler,
   pygobject_constructv,
   pygobject_construct,
-  pyg_set_object_has_new_constructor
+  pyg_set_object_has_new_constructor,
+
+  set_log_handler,
+  disable_log_handlers
 };

 #define REGISTER_TYPE(d, type, name) \
@@ -3293,12 +3342,9 @@ init_gobject(void)

     warning = PyErr_NewException("gobject.Warning", PyExc_Warning, NULL);
     PyDict_SetItemString(d, "Warning", warning);
-    g_log_set_handler("GLib", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
-                      _log_func, warning);
-    g_log_set_handler("GLib-GObject", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
-                      _log_func, warning);
-    g_log_set_handler("GThread", G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING,
-                      _log_func, warning);
+    set_log_handler("GLib", warning);
+    set_log_handler("GLib-GObject", warning);
+    set_log_handler("GThread", warning);

       /* signal registration recognizes this special accumulator 'constant' */
     _pyg_signal_accumulator_true_handled_func = \
Index: gobject/pygobject.h
===================================================================
RCS file: /cvs/gnome/gnome-python/pygobject/gobject/pygobject.h,v
retrieving revision 1.58
diff -u -p -r1.58 pygobject.h
--- gobject/pygobject.h	15 Apr 2006 16:47:06 -0000	1.58
+++ gobject/pygobject.h	6 May 2006 17:51:19 -0000
@@ -172,6 +172,10 @@ struct _PyGObject_Functions {
                                       const char *first_property_name,
                                       ...);
     void      (*set_object_has_new_constructor) (GType type);
+
+    void      (*set_log_handler) (const char *domain,
+                                  PyObject   *warning);
+    void      (*disable_log_handlers) (void);
 };

 #ifndef _INSIDE_PYGOBJECT_
@@ -231,6 +235,8 @@ struct _PyGObject_Functions *_PyGObject_
 #define pygobject_construct         (_PyGObject_API->pygobject_construct)
 #define pygobject_constructv        (_PyGObject_API->pygobject_constructv)
 #define pyg_set_object_has_new_constructor (_PyGObject_API->set_object_has_new_constructor)
+#define pyg_set_log_handler	    (_PyGObject_API->set_log_handler)
+#define pyg_disable_log_handlers    (_PyGObject_API->disable_log_handlers)


 #define pyg_block_threads()   G_STMT_START {   \
