[Spice-commits] 2 commits - common/log.c tests/test-logging.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 6 13:21:45 UTC 2019


 common/log.c         |  118 ---------------------------------------------------
 tests/test-logging.c |  104 --------------------------------------------
 2 files changed, 1 insertion(+), 221 deletions(-)

New commits:
commit e3af47fe9d015936db0bc98e7e0841c51d6ed6d9
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jun 13 15:40:45 2017 +0100

    log: remove deprecated SPICE_DEBUG_LEVEL support
    
    This feature was marked obsolete by efd1d3cb4d8eee more than
    three years ago.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.c b/common/log.c
index 7cc4077..f9cdd60 100644
--- a/common/log.c
+++ b/common/log.c
@@ -32,93 +32,10 @@
 #include "log.h"
 #include "backtrace.h"
 
-static int glib_debug_level = INT_MAX;
-
 #define G_LOG_DOMAIN "Spice"
 
-typedef enum {
-    SPICE_LOG_LEVEL_ERROR,
-    SPICE_LOG_LEVEL_CRITICAL,
-    SPICE_LOG_LEVEL_WARNING,
-    SPICE_LOG_LEVEL_INFO,
-    SPICE_LOG_LEVEL_DEBUG,
-} SpiceLogLevel;
-
-static GLogLevelFlags spice_log_level_to_glib(SpiceLogLevel level)
-{
-    static const GLogLevelFlags glib_levels[] = {
-        [ SPICE_LOG_LEVEL_ERROR ] = G_LOG_LEVEL_ERROR,
-        [ SPICE_LOG_LEVEL_CRITICAL ] = G_LOG_LEVEL_CRITICAL,
-        [ SPICE_LOG_LEVEL_WARNING ] = G_LOG_LEVEL_WARNING,
-        [ SPICE_LOG_LEVEL_INFO ] = G_LOG_LEVEL_INFO,
-        [ SPICE_LOG_LEVEL_DEBUG ] = G_LOG_LEVEL_DEBUG,
-    };
-    g_return_val_if_fail (level >= 0, G_LOG_LEVEL_ERROR);
-    g_return_val_if_fail (level < G_N_ELEMENTS(glib_levels), G_LOG_LEVEL_DEBUG);
-
-    return glib_levels[level];
-}
-
-static void spice_log_set_debug_level(void)
-{
-    if (glib_debug_level == INT_MAX) {
-        const char *debug_str = g_getenv("SPICE_DEBUG_LEVEL");
-        if (debug_str != NULL) {
-            int debug_level;
-            char *debug_env;
-
-            /* FIXME: To be removed after enough deprecation time */
-            g_warning("Setting SPICE_DEBUG_LEVEL is deprecated, use G_MESSAGES_DEBUG instead");
-            debug_level = atoi(debug_str);
-            if (debug_level > SPICE_LOG_LEVEL_DEBUG) {
-                debug_level = SPICE_LOG_LEVEL_DEBUG;
-            }
-            glib_debug_level = spice_log_level_to_glib(debug_level);
-
-            /* If the debug level is too high, make sure we don't try to enable
-             * display of glib debug logs */
-            if (debug_level < SPICE_LOG_LEVEL_INFO)
-                return;
-
-            /* Make sure GLib default log handler will show the debug messages. Messing with
-             * environment variables like this is ugly, but this only happens when the legacy
-             * SPICE_DEBUG_LEVEL is used
-             */
-            debug_env = (char *)g_getenv("G_MESSAGES_DEBUG");
-            if (debug_env == NULL) {
-                g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, FALSE);
-            } else {
-                debug_env = g_strconcat(debug_env, " ", G_LOG_DOMAIN, NULL);
-                g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, FALSE);
-                g_free(debug_env);
-            }
-        }
-    }
-}
-
-static void spice_logger(const gchar *log_domain,
-                         GLogLevelFlags log_level,
-                         const gchar *message,
-                         gpointer user_data G_GNUC_UNUSED)
-{
-    if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level) {
-        return; // do not print anything
-    }
-    g_log_default_handler(log_domain, log_level, message, NULL);
-}
-
 SPICE_CONSTRUCTOR_FUNC(spice_log_init)
 {
-
-    spice_log_set_debug_level();
-    if (glib_debug_level != INT_MAX) {
-        /* If SPICE_DEBUG_LEVEL is set, we need a custom handler, which is
-         * going to break use of g_log_set_default_handler() by apps
-         */
-        g_log_set_handler(G_LOG_DOMAIN,
-                          G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
-                          spice_logger, NULL);
-    }
     /* Threading is always enabled from 2.31.0 onwards */
     /* Our logging is potentially used from different threads.
      * Older glibs require that g_thread_init() is called when
@@ -139,10 +56,6 @@ static void spice_logv(const char *log_domain,
 {
     GString *log_msg;
 
-    if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level) {
-        return; // do not print anything
-    }
-
     log_msg = g_string_new(NULL);
     if (strloc && function) {
         g_string_append_printf(log_msg, "%s:%s: ", strloc, function);
diff --git a/tests/test-logging.c b/tests/test-logging.c
index 3b17f44..ff2d8bd 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -217,71 +217,6 @@ static void test_log_levels(void)
     g_test_trap_assert_stdout_unmatched("*other_debug*");
 }
 
-/* Checks that SPICE_DEBUG_LEVEL impacts spice_debug(), g_debug() but not other_debug() */
-static void test_spice_debug_level(void)
-{
-    if (g_test_subprocess()) {
-        /* g_test_expected_message only checks whether the appropriate messages got up to g_log()
-         * The following calls will be caught by the parent process to check what was (not) printed
-         * to stdout/stderr
-         */
-        spice_info("spice_info");
-        g_debug("g_debug");
-        spice_debug("spice_debug");
-        other_debug("other_debug");
-
-        return;
-    }
-
-    g_unsetenv("G_MESSAGES_DEBUG");
-    g_setenv("SPICE_DEBUG_LEVEL", "5", TRUE);
-    g_test_trap_subprocess(NULL, 0, 0);
-    g_unsetenv("SPICE_DEBUG_LEVEL");
-    g_test_trap_assert_passed();
-    g_test_trap_assert_stderr("*SPICE_DEBUG_LEVEL*deprecated*");
-    g_test_trap_assert_stdout("*spice_info\n*g_debug\n*spice_debug\n");
-    g_test_trap_assert_stdout_unmatched("*other_debug*");
-}
-
-/* Checks that raising SPICE_DEBUG_LEVEL allows to only show spice_warning() and spice_critical()
- * messages, as well as g_warning() and g_critical(), but does not impact other_message()
- */
-static void test_spice_debug_level_warning(void)
-{
-    if (g_test_subprocess()) {
-        spice_info("spice_info");
-        spice_debug("spice_debug");
-        spice_warning("spice_warning");
-        g_debug("g_debug");
-        g_info("g_info");
-        g_message("g_message");
-        g_warning("g_warning");
-        g_critical("g_critical");
-        other_debug("other_debug");
-        other_info("other_info");
-        other_message("other_message");
-        other_warning("other_warning");
-        other_critical("other_critical");
-
-        return;
-    }
-
-    g_setenv("SPICE_DEBUG_LEVEL", "1", TRUE);
-    g_test_trap_subprocess(NULL, 0, 0);
-    g_unsetenv("SPICE_DEBUG_LEVEL");
-    g_test_trap_assert_passed();
-    g_test_trap_assert_stderr("*SPICE_DEBUG_LEVEL*deprecated*");
-    g_test_trap_assert_stderr("*g_critical\n*other_message\n*other_warning\n*other_critical\n");
-    g_test_trap_assert_stdout_unmatched("*spice_info*");
-    g_test_trap_assert_stdout_unmatched("*spice_debug*");
-    g_test_trap_assert_stderr_unmatched("*spice_warning*");
-    g_test_trap_assert_stdout_unmatched("*g_debug*");
-    g_test_trap_assert_stdout_unmatched("*g_info*");
-    g_test_trap_assert_stderr_unmatched("*g_message*");
-    g_test_trap_assert_stderr_unmatched("*g_warning*");
-    g_test_trap_assert_stdout_unmatched("*other_info*");
-}
-
 /* Checks that setting G_MESSAGES_DEBUG to 'Spice' impacts spice_debug() and
  * g_debug() but not other_debug() */
 static void test_spice_g_messages_debug(void)
@@ -358,8 +293,6 @@ int main(int argc, char **argv)
     g_log_set_always_fatal(fatal_mask & G_LOG_LEVEL_MASK);
 
 #if GLIB_CHECK_VERSION(2,38,0)
-    g_test_add_func("/spice-common/spice-debug-level", test_spice_debug_level);
-    g_test_add_func("/spice-common/spice-debug-level-warning", test_spice_debug_level_warning);
     g_test_add_func("/spice-common/spice-g-messages-debug", test_spice_g_messages_debug);
     g_test_add_func("/spice-common/spice-g-messages-debug-all", test_spice_g_messages_debug_all);
     g_test_add_func("/spice-common/spice-log-levels", test_log_levels);
commit ea20b8c0136c7e5a55cd32d3f23fad5db07bd401
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Jun 13 15:31:34 2017 +0100

    log: remove deprecated SPICE_ABORT_LEVEL support
    
    This feature was marked obsolete by efd1d3cb4d8eee more than
    three years ago.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.c b/common/log.c
index a7806c5..7cc4077 100644
--- a/common/log.c
+++ b/common/log.c
@@ -33,11 +33,6 @@
 #include "backtrace.h"
 
 static int glib_debug_level = INT_MAX;
-static int abort_mask = 0;
-
-#ifndef SPICE_ABORT_MASK_DEFAULT
-#define SPICE_ABORT_MASK_DEFAULT (G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_ERROR)
-#endif
 
 #define G_LOG_DOMAIN "Spice"
 
@@ -101,29 +96,6 @@ static void spice_log_set_debug_level(void)
     }
 }
 
-static void spice_log_set_abort_level(void)
-{
-    if (abort_mask == 0) {
-        const char *abort_str = g_getenv("SPICE_ABORT_LEVEL");
-        if (abort_str != NULL) {
-            GLogLevelFlags glib_abort_level;
-
-            /* FIXME: To be removed after enough deprecation time */
-            g_warning("Setting SPICE_ABORT_LEVEL is deprecated, use G_DEBUG instead");
-            glib_abort_level = spice_log_level_to_glib(atoi(abort_str));
-            unsigned int fatal_mask = G_LOG_FATAL_MASK;
-            while (glib_abort_level >= G_LOG_LEVEL_ERROR) {
-                fatal_mask |= glib_abort_level;
-                glib_abort_level >>= 1;
-            }
-            abort_mask = fatal_mask;
-            g_log_set_fatal_mask(G_LOG_DOMAIN, fatal_mask);
-        } else {
-            abort_mask = SPICE_ABORT_MASK_DEFAULT;
-        }
-    }
-}
-
 static void spice_logger(const gchar *log_domain,
                          GLogLevelFlags log_level,
                          const gchar *message,
@@ -139,7 +111,6 @@ SPICE_CONSTRUCTOR_FUNC(spice_log_init)
 {
 
     spice_log_set_debug_level();
-    spice_log_set_abort_level();
     if (glib_debug_level != INT_MAX) {
         /* If SPICE_DEBUG_LEVEL is set, we need a custom handler, which is
          * going to break use of g_log_set_default_handler() by apps
@@ -182,7 +153,7 @@ static void spice_logv(const char *log_domain,
     g_log(log_domain, log_level, "%s", log_msg->str);
     g_string_free(log_msg, TRUE);
 
-    if ((abort_mask & log_level) != 0) {
+    if ((log_level & G_LOG_LEVEL_CRITICAL) != 0) {
         spice_backtrace();
         abort();
     }
diff --git a/tests/test-logging.c b/tests/test-logging.c
index 559d656..3b17f44 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -44,37 +44,6 @@ LOG_OTHER_HELPER(warning, WARNING)
 LOG_OTHER_HELPER(critical, CRITICAL)
 
 #if GLIB_CHECK_VERSION(2,38,0)
-/* Checks that spice_warning() aborts after changing SPICE_ABORT_LEVEL */
-static void test_spice_abort_level(void)
-{
-    if (g_test_subprocess()) {
-        spice_warning("spice_warning");
-        return;
-    }
-    /* 2 = SPICE_LOG_LEVEL_WARNING  */
-    g_setenv("SPICE_ABORT_LEVEL", "2", TRUE);
-    g_test_trap_subprocess(NULL, 0, 0);
-    g_unsetenv("SPICE_ABORT_LEVEL");
-    g_test_trap_assert_failed();
-    g_test_trap_assert_stderr("*SPICE_ABORT_LEVEL*deprecated*");
-    g_test_trap_assert_stderr("*spice_warning*");
-}
-
-/* Checks that g_warning() aborts after changing SPICE_ABORT_LEVEL */
-static void test_spice_abort_level_g_warning(void)
-{
-    if (g_test_subprocess()) {
-        g_warning("g_warning");
-        return;
-    }
-    g_setenv("SPICE_ABORT_LEVEL", "2", TRUE);
-    g_test_trap_subprocess(NULL, 0, 0);
-    g_unsetenv("SPICE_ABORT_LEVEL");
-    g_test_trap_assert_failed();
-    g_test_trap_assert_stderr("*SPICE_ABORT_LEVEL*deprecated*");
-    g_test_trap_assert_stderr("*g_warning*");
-}
-
 /* Checks that spice_warning() aborts after setting G_DEBUG=fatal-warnings */
 static void test_spice_fatal_warning(void)
 {
@@ -283,7 +252,6 @@ static void test_spice_debug_level_warning(void)
         spice_info("spice_info");
         spice_debug("spice_debug");
         spice_warning("spice_warning");
-        spice_critical("spice_critical");
         g_debug("g_debug");
         g_info("g_info");
         g_message("g_message");
@@ -298,15 +266,12 @@ static void test_spice_debug_level_warning(void)
         return;
     }
 
-    g_setenv("SPICE_ABORT_LEVEL", "0", TRUE);
     g_setenv("SPICE_DEBUG_LEVEL", "1", TRUE);
     g_test_trap_subprocess(NULL, 0, 0);
-    g_unsetenv("SPICE_ABORT_LEVEL");
     g_unsetenv("SPICE_DEBUG_LEVEL");
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("*SPICE_DEBUG_LEVEL*deprecated*");
-    g_test_trap_assert_stderr("*SPICE_ABORT_LEVEL*deprecated*");
-    g_test_trap_assert_stderr("*spice_critical\n*g_critical\n*other_message\n*other_warning\n*other_critical\n");
+    g_test_trap_assert_stderr("*g_critical\n*other_message\n*other_warning\n*other_critical\n");
     g_test_trap_assert_stdout_unmatched("*spice_info*");
     g_test_trap_assert_stdout_unmatched("*spice_debug*");
     g_test_trap_assert_stderr_unmatched("*spice_warning*");
@@ -393,8 +358,6 @@ int main(int argc, char **argv)
     g_log_set_always_fatal(fatal_mask & G_LOG_LEVEL_MASK);
 
 #if GLIB_CHECK_VERSION(2,38,0)
-    g_test_add_func("/spice-common/spice-abort-level", test_spice_abort_level);
-    g_test_add_func("/spice-common/spice-abort-level-gwarning", test_spice_abort_level_g_warning);
     g_test_add_func("/spice-common/spice-debug-level", test_spice_debug_level);
     g_test_add_func("/spice-common/spice-debug-level-warning", test_spice_debug_level_warning);
     g_test_add_func("/spice-common/spice-g-messages-debug", test_spice_g_messages_debug);


More information about the Spice-commits mailing list