1From 71f6d4c129fc729a5ead08637924d8c0973f2fe9 Mon Sep 17 00:00:00 2001 2From: Alexander Slobodeniuk <aslobodeniuk@fluendo.com> 3Date: Wed, 1 Nov 2023 10:32:27 +0100 4Subject: [PATCH 1/2] gmessages: fix dropping irrelevant log domains 5 6If the string of one log domain is contained in 7another, it was printing both. 8 9For example, if G_MESSAGES_DEBUG is "Gtkspecial", 10it would also keep the logs of the "Gtk" domain 11 12Conflict:NA 13Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/71f6d4c129fc729a5ead08637924d8c0973f2fe9 14 15--- 16 glib/gmessages.c | 22 +++++++++++++++++++++- 17 1 file changed, 21 insertions(+), 1 deletion(-) 18 19diff --git a/glib/gmessages.c b/glib/gmessages.c 20index d0d38c925a..ebd3a5433e 100644 21--- a/glib/gmessages.c 22+++ b/glib/gmessages.c 23@@ -2465,6 +2465,26 @@ log_is_old_api (const GLogField *fields, 24 g_strcmp0 (fields[0].value, "1") == 0); 25 } 26 27+static gboolean 28+domain_found (const gchar *domains, 29+ const char *log_domain) 30+{ 31+ guint len; 32+ const gchar *found; 33+ 34+ len = strlen (log_domain); 35+ 36+ for (found = strstr (domains, log_domain); found; 37+ found = strstr (found + 1, log_domain)) 38+ { 39+ if ((found == domains || found[-1] == ' ') 40+ && (found[len] == 0 || found[len] == ' ')) 41+ return TRUE; 42+ } 43+ 44+ return FALSE; 45+} 46+ 47 /* 48 * Internal version of g_log_writer_default_would_drop(), which can 49 * read from either a log_domain or an array of fields. This avoids 50@@ -2504,7 +2524,7 @@ should_drop_message (GLogLevelFlags log_level, 51 } 52 53 if (strcmp (domains, "all") != 0 && 54- (log_domain == NULL || !strstr (domains, log_domain))) 55+ (log_domain == NULL || !domain_found (domains, log_domain))) 56 return TRUE; 57 } 58 59-- 60GitLab 61 62 63From 8eddbb9832b9a52a7495cc380e53715d920bb9ea Mon Sep 17 00:00:00 2001 64From: Alexander Slobodeniuk <aslobodeniuk@fluendo.com> 65Date: Wed, 1 Nov 2023 19:23:35 +0100 66Subject: [PATCH 2/2] glib/tests: extend logging test (dropping domains) 67 68 69Conflict:NA 70Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/8eddbb9832b9a52a7495cc380e53715d920bb9ea 71 72--- 73 glib/tests/logging.c | 40 ++++++++++++++++++++++++++++++++++++++++ 74 1 file changed, 40 insertions(+) 75 76diff --git a/glib/tests/logging.c b/glib/tests/logging.c 77index ea9dcb825e..f4c47e16c8 100644 78--- a/glib/tests/logging.c 79+++ b/glib/tests/logging.c 80@@ -244,6 +244,46 @@ test_default_handler_would_drop (void) 81 g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 82 g_assert_false (g_log_writer_default_would_drop (1<<G_LOG_LEVEL_USER_SHIFT, "foo")); 83 84+ g_setenv ("G_MESSAGES_DEBUG", "foobar", TRUE); 85+ 86+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 87+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 88+ 89+ g_setenv ("G_MESSAGES_DEBUG", "foobar bar", TRUE); 90+ 91+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 92+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 93+ 94+ g_setenv ("G_MESSAGES_DEBUG", "foobar bar barfoo", TRUE); 95+ 96+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 97+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 98+ 99+ g_setenv ("G_MESSAGES_DEBUG", "foobar bar foo barfoo", TRUE); 100+ 101+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 102+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 103+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz")); 104+ 105+ g_setenv ("G_MESSAGES_DEBUG", "foo bar baz", TRUE); 106+ 107+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 108+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 109+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz")); 110+ 111+ g_setenv ("G_MESSAGES_DEBUG", "foo", TRUE); 112+ 113+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 114+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 115+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foobarbaz")); 116+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "barfoobaz")); 117+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "barbazfoo")); 118+ 119+ g_setenv ("G_MESSAGES_DEBUG", " foo bar foobaz ", TRUE); 120+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo")); 121+ g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar")); 122+ g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz")); 123+ 124 exit (0); 125 } 126 127-- 128GitLab