[Spice-devel] [PATCH spice-common 3/3] log: Check log level from spice_logv

Frediano Ziglio fziglio at redhat.com
Wed May 31 07:53:56 UTC 2017


This was suggested by Christophe de Dinechin as an optimisation.
Most of the messages won't be processed for formatting.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 common/log.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/common/log.c b/common/log.c
index dae955a..bab1afa 100644
--- a/common/log.c
+++ b/common/log.c
@@ -153,6 +153,11 @@ static void spice_logv(const char *log_domain,
                        va_list args)
 {
     GString *log_msg;
+    GLogLevelFlags glib_level = spice_log_level_to_glib(log_level);
+
+    if ((glib_level & G_LOG_LEVEL_MASK) > glib_debug_level) {
+            return; // do not print anything
+    }
 
     log_msg = g_string_new(NULL);
     if (strloc && function) {
@@ -161,7 +166,7 @@ static void spice_logv(const char *log_domain,
     if (format) {
         g_string_append_vprintf(log_msg, format, args);
     }
-    g_log(log_domain, spice_log_level_to_glib(log_level), "%s", log_msg->str);
+    g_log(log_domain, glib_level, "%s", log_msg->str);
     g_string_free(log_msg, TRUE);
 
     if (abort_level != -1 && abort_level >= (int) log_level) {
-- 
2.9.4



More information about the Spice-devel mailing list