gstinfo: Reduce code duplication around level pattern matching

Move the match, logging and set_threshold to a new function.

The log levels are different, so choose the higher one (LOG). Having two
equivalent messages at two different levels seems like a bad idea
anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=794717
This commit is contained in:
Jan Alexander Steffens (heftig) 2018-03-27 10:14:27 +02:00 committed by Tim-Philipp Müller
parent 8117a29408
commit b12df466f2

View file

@ -1577,6 +1577,20 @@ gst_debug_get_default_threshold (void)
return (GstDebugLevel) g_atomic_int_get (&__default_level);
}
static gboolean
gst_debug_apply_entry (GstDebugCategory * cat, LevelNameEntry * entry)
{
if (!g_pattern_match_string (entry->pat, cat->name))
return FALSE;
if (gst_is_initialized ())
GST_LOG ("category %s matches pattern %p - gets set to level %d",
cat->name, entry->pat, entry->level);
gst_debug_category_set_threshold (cat, entry->level);
return TRUE;
}
static void
gst_debug_reset_threshold (gpointer category, gpointer unused)
{
@ -1589,13 +1603,8 @@ gst_debug_reset_threshold (gpointer category, gpointer unused)
LevelNameEntry *entry = walk->data;
walk = g_slist_next (walk);
if (g_pattern_match_string (entry->pat, cat->name)) {
if (gst_is_initialized ())
GST_LOG ("category %s matches pattern %p - gets set to level %d",
cat->name, entry->pat, entry->level);
gst_debug_category_set_threshold (cat, entry->level);
if (gst_debug_apply_entry (cat, entry))
goto exit;
}
}
gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
@ -1617,12 +1626,7 @@ for_each_threshold_by_entry (gpointer data, gpointer user_data)
GstDebugCategory *cat = (GstDebugCategory *) data;
LevelNameEntry *entry = (LevelNameEntry *) user_data;
if (g_pattern_match_string (entry->pat, cat->name)) {
if (gst_is_initialized ())
GST_TRACE ("category %s matches pattern %p - gets set to level %d",
cat->name, entry->pat, entry->level);
gst_debug_category_set_threshold (cat, entry->level);
}
gst_debug_apply_entry (cat, entry);
}
/**