info: make it possible to remove default log handler before gst_init()
authorTim-Philipp Müller <tim@centricular.com>
Mon, 29 Feb 2016 19:04:16 +0000 (19:04 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 26 Mar 2016 11:40:43 +0000 (11:40 +0000)
Make sure it's not even added then, so that we never output
anything via the default log handler then.

https://bugzilla.gnome.org/show_bug.cgi?id=751538

gst/gstinfo.c

index 8bfa33b..d9e9d11 100644 (file)
@@ -253,6 +253,9 @@ LogFuncEntry;
 static GMutex __log_func_mutex;
 static GSList *__log_functions = NULL;
 
+/* whether to add the default log function in gst_init() */
+static gboolean add_default_log_func = TRUE;
+
 #define PRETTY_TAGS_DEFAULT  TRUE
 static gboolean pretty_tags = PRETTY_TAGS_DEFAULT;
 
@@ -321,7 +324,8 @@ _priv_gst_debug_init (void)
   _GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
       GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, "debugging subsystem");
 
-  gst_debug_add_log_function (gst_debug_log_default, log_file, NULL);
+  if (add_default_log_func)
+    gst_debug_add_log_function (gst_debug_log_default, log_file, NULL);
 
   /* FIXME: add descriptions here */
   GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
@@ -1265,9 +1269,18 @@ gst_debug_remove_log_function (GstLogFunction func)
   removals =
       gst_debug_remove_with_compare_func
       (gst_debug_compare_log_function_by_func, (gpointer) func);
-  if (gst_is_initialized ())
+
+  if (gst_is_initialized ()) {
     GST_DEBUG ("removed log function %p %d times from log function list", func,
         removals);
+  } else {
+    /* If the default log function is removed before gst_init() was called,
+     * set a flag so we don't add it in gst_init() later */
+    if (func == gst_debug_log_default) {
+      add_default_log_func = FALSE;
+      ++removals;
+    }
+  }
 
   return removals;
 }