From 580af16fe18b590a83db0c5a576e6db5fc3d61c7 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Sat, 22 Jan 2011 01:31:21 -0800 Subject: [PATCH] moo_test_set_silent_messages() --- moo/mooutils/moo-test-utils.c | 35 +++++++++++++++++++++++++++++++++++ moo/mooutils/moo-test-utils.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/moo/mooutils/moo-test-utils.c b/moo/mooutils/moo-test-utils.c index d57e4776..25db3639 100644 --- a/moo/mooutils/moo-test-utils.c +++ b/moo/mooutils/moo-test-utils.c @@ -595,3 +595,38 @@ moo_test_coverage_record (const char *lang, g_strdup_printf ("%s.%s", lang, function), GINT_TO_POINTER (TRUE)); } + + +/************************************************************************************ + * log handlers + */ + +static gboolean silent_messages; + +static void +silent_log_handler (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer data) +{ + if (log_level & G_LOG_LEVEL_ERROR) + g_log_default_handler (log_domain, log_level, message, data); +} + +/** + * moo_test_set_silent_messages: + **/ +gboolean +moo_test_set_silent_messages (gboolean silent) +{ + if (silent == silent_messages) + return silent_messages; + + if (silent) + g_log_set_default_handler (silent_log_handler, NULL); + else + g_log_set_default_handler (g_log_default_handler, NULL); + + silent_messages = silent; + return !silent; +} diff --git a/moo/mooutils/moo-test-utils.h b/moo/mooutils/moo-test-utils.h index e9ca2fb1..5cf02e5c 100644 --- a/moo/mooutils/moo-test-utils.h +++ b/moo/mooutils/moo-test-utils.h @@ -85,6 +85,8 @@ void moo_test_coverage_write (const char *filename); void moo_test_coverage_record (const char *lang, const char *function); +gboolean moo_test_set_silent_messages (gboolean silent); + G_END_DECLS