From bfe76bf1d10a77f18baadd590794c4c529380549 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Mon, 11 May 2020 17:24:40 +0300 Subject: [PATCH] debug: honor WIREPLUMBER_DEBUG and ignore PIPEWIRE_DEBUG in pw_log And also provide a way to disable this integration at runtime to get pipewire's log back, with WIREPLUMBER_NO_PW_LOG=1 --- lib/wp/debug.c | 10 +++++++--- lib/wp/wp.c | 14 +++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/wp/debug.c b/lib/wp/debug.c index a7ba31ee..52aa584d 100644 --- a/lib/wp/debug.c +++ b/lib/wp/debug.c @@ -109,11 +109,12 @@ wp_debug_initialize (void) debug = g_getenv ("WIREPLUMBER_DEBUG"); if (debug && debug[0] != '\0') { - /* WP_DEBUG=level:category1,category2 */ + /* WIREPLUMBER_DEBUG=level:category1,category2 */ tokens = pw_split_strv (debug, ":", 2, &n_tokens); /* set the log level */ enabled_level = atoi (tokens[0]); + enabled_level = CLAMP (enabled_level, 0, G_N_ELEMENTS (log_level_info) - 1); /* enable filtering of debug categories */ if (n_tokens > 1) { @@ -133,6 +134,9 @@ wp_debug_initialize (void) use_color = g_log_writer_supports_color (fileno (stderr)); output_is_journal = g_log_writer_is_journald (fileno (stderr)); + /* set the log level also on the spa_log */ + wp_spa_log_get_instance()->level = log_level_info[enabled_level].spa_level; + if (categories) pw_free_strv (categories); if (tokens) @@ -363,7 +367,7 @@ wp_spa_log_logv (void *object, { "CODE_LINE", line_str, -1 }, { "CODE_FUNC", func, -1 }, { "MESSAGE", NULL, -1 }, - { "GLIB_DOMAIN", "pw-lib", -1 }, + { "GLIB_DOMAIN", "pw", -1 }, }; gint log_level_idx = spa_log_level_index (level); @@ -398,7 +402,7 @@ static const struct spa_log_methods wp_spa_log_methods = { static struct spa_log wp_spa_log = { .iface = { SPA_TYPE_INTERFACE_Log, SPA_VERSION_LOG, { &wp_spa_log_methods, NULL } }, - .level = SPA_LOG_LEVEL_INFO, + .level = SPA_LOG_LEVEL_WARN, }; struct spa_log * diff --git a/lib/wp/wp.c b/lib/wp/wp.c index ecabd559..c2feb3f3 100644 --- a/lib/wp/wp.c +++ b/lib/wp/wp.c @@ -42,18 +42,26 @@ void wp_init (WpInitFlags flags) { - if (flags & WP_INIT_SET_PW_LOG) - pw_log_set (wp_spa_log_get_instance ()); + enum spa_log_level lvl = 0; if (flags & WP_INIT_SET_GLIB_LOG) g_log_set_writer_func (wp_log_writer_default, NULL, NULL); /* a dummy message, to initialize the logging system */ - wp_message ("WirePlumber initializing"); + wp_info ("WirePlumber initializing"); + + if (flags & WP_INIT_SET_PW_LOG && !g_getenv ("WIREPLUMBER_NO_PW_LOG")) { + pw_log_level = lvl = wp_spa_log_get_instance ()->level; + pw_log_set (wp_spa_log_get_instance ()); + } if (flags & WP_INIT_PIPEWIRE) pw_init (NULL, NULL); + /* restore our log level to override PIPEWIRE_DEBUG */ + if (flags & WP_INIT_SET_PW_LOG && !g_getenv ("WIREPLUMBER_NO_PW_LOG")) + pw_log_set_level (lvl); + if (flags & WP_INIT_SPA_TYPES) { wp_spa_type_init (TRUE);