[Spice-devel] [spice-common 1/2] log: Only install glib log handler if SPICE_DEBUG_LEVEL is set
Christophe Fergeau
cfergeau at redhat.com
Wed Jun 20 14:02:47 UTC 2018
Calling g_log_set_handler() is problematic as this means applications
using spice-server won't be able to use g_log_set_default_handler to
manage spice logging output themselves. Since this call is only needed
for backwards compatibility (so that calling g_log together with
SPICE_DEBUG_LEVEL set has the expected behaviour), we can install it
only when SPICE_DEBUG_LEVEL is set.
Then we should deprecate SPICE_DEBUG_LEVEL once and for all.
---
common/log.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/common/log.c b/common/log.c
index 9b4757b..7e460f0 100644
--- a/common/log.c
+++ b/common/log.c
@@ -142,9 +142,14 @@ SPICE_CONSTRUCTOR_FUNC(spice_log_init)
spice_log_set_debug_level();
spice_log_set_abort_level();
- g_log_set_handler(G_LOG_DOMAIN,
- G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
- spice_logger, NULL);
+ 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
--
2.17.1
More information about the Spice-devel
mailing list