mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Merge branch 'fix-gmessage-domain-drop' into 'main'
gmessages: fix dropping irrelevant log domains See merge request GNOME/glib!3679
This commit is contained in:
commit
c1eb8ded7b
@ -2465,6 +2465,26 @@ log_is_old_api (const GLogField *fields,
|
||||
g_strcmp0 (fields[0].value, "1") == 0);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
domain_found (const gchar *domains,
|
||||
const char *log_domain)
|
||||
{
|
||||
guint len;
|
||||
const gchar *found;
|
||||
|
||||
len = strlen (log_domain);
|
||||
|
||||
for (found = strstr (domains, log_domain); found;
|
||||
found = strstr (found + 1, log_domain))
|
||||
{
|
||||
if ((found == domains || found[-1] == ' ')
|
||||
&& (found[len] == 0 || found[len] == ' '))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal version of g_log_writer_default_would_drop(), which can
|
||||
* read from either a log_domain or an array of fields. This avoids
|
||||
@ -2504,7 +2524,7 @@ should_drop_message (GLogLevelFlags log_level,
|
||||
}
|
||||
|
||||
if (strcmp (domains, "all") != 0 &&
|
||||
(log_domain == NULL || !strstr (domains, log_domain)))
|
||||
(log_domain == NULL || !domain_found (domains, log_domain)))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -244,6 +244,46 @@ test_default_handler_would_drop (void)
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_false (g_log_writer_default_would_drop (1<<G_LOG_LEVEL_USER_SHIFT, "foo"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", "foobar", TRUE);
|
||||
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", "foobar bar", TRUE);
|
||||
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", "foobar bar barfoo", TRUE);
|
||||
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", "foobar bar foo barfoo", TRUE);
|
||||
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", "foo bar baz", TRUE);
|
||||
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", "foo", TRUE);
|
||||
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foobarbaz"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "barfoobaz"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "barbazfoo"));
|
||||
|
||||
g_setenv ("G_MESSAGES_DEBUG", " foo bar foobaz ", TRUE);
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
|
||||
g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
|
||||
g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz"));
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user