From 11d35f99be565c15a37d1522d5eddb9bdc10b551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 9 Jun 2022 16:32:42 +0200 Subject: [PATCH] util: Make meta_topic() log using the debug level in tests Some tests expect warnings to be logged, and handle that using g_test_expect_message(). However, if debug topics are enabled, this causes g_logv() to expect expected messages to also contain entries with the debug level 'message' or higher to be listed in the expected message list. Since meta_topic() always logged using g_message(), enabling debug topics caused any test that used g_test_expect_message() and had debug logging somewhere along the code path to fail. Fix this by changing the log level of meta_topic() to 'debug' if we're in a test. This doesn't mean they won't be visible, they still will since debug log entries are printed by default during testing. Part-of: --- src/core/util.c | 14 ++++++++++++++ src/meta/util.h | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/util.c b/src/core/util.c index ea26bc2f0..fddd06fdd 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -79,6 +79,7 @@ static const GDebugKey meta_debug_keys[] = { static gint verbose_topics = 0; static gboolean is_wayland_compositor = FALSE; static int debug_paint_flags = 0; +static GLogLevelFlags mutter_log_level = G_LOG_LEVEL_MESSAGE; #ifdef WITH_VERBOSE_MODE static FILE* logfile = NULL; @@ -213,6 +214,9 @@ meta_init_debug_utils (void) G_N_ELEMENTS (meta_debug_keys)); meta_add_verbose_topic (topics); } + + if (g_test_initialized ()) + mutter_log_level = G_LOG_LEVEL_DEBUG; } gboolean @@ -584,3 +588,13 @@ meta_get_debug_paint_flags (void) { return debug_paint_flags; } + +void +meta_log (const char *format, ...) +{ + va_list args; + + va_start (args, format); + g_logv (G_LOG_DOMAIN, mutter_log_level, format, args); + va_end (args); +} diff --git a/src/meta/util.h b/src/meta/util.h index d61fa85d8..bb2e875c1 100644 --- a/src/meta/util.h +++ b/src/meta/util.h @@ -157,6 +157,9 @@ char* meta_g_utf8_strndup (const gchar *src, gsize n); const char * meta_topic_to_string (MetaDebugTopic topic); +META_EXPORT +void meta_log (const char *format, ...) G_GNUC_PRINTF (1, 2); + #define meta_topic(debug_topic, ...) \ G_STMT_START \ { \ @@ -165,7 +168,7 @@ const char * meta_topic_to_string (MetaDebugTopic topic); g_autofree char *_topic_message = NULL; \ \ _topic_message = g_strdup_printf (__VA_ARGS__); \ - g_message ("%s: %s", meta_topic_to_string (debug_topic), \ + meta_log ("%s: %s", meta_topic_to_string (debug_topic), \ _topic_message); \ } \ } \