[gnome-software/mwleeds/honor-g-messages-debug: 1/2] Honor G_MESSAGES_DEBUG env var
- From: Phaedrus Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/mwleeds/honor-g-messages-debug: 1/2] Honor G_MESSAGES_DEBUG env var
- Date: Thu, 18 Feb 2021 07:48:29 +0000 (UTC)
commit 4c633a14d5468a2989c6a66884288cd8cb630ef6
Author: Phaedrus Leeds <mwleeds endlessos org>
Date: Wed Feb 17 11:46:48 2021 -0800
Honor G_MESSAGES_DEBUG env var
Instead of requiring the --verbose command line argument, also respect
the G_MESSAGES_DEBUG environment variable, as is standard for GLib-based
applications.
lib/gs-debug.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/lib/gs-debug.c b/lib/gs-debug.c
index af278495b..c269f6bb6 100644
--- a/lib/gs-debug.c
+++ b/lib/gs-debug.c
@@ -30,15 +30,22 @@ gs_log_writer_console (GLogLevelFlags log_level,
gpointer user_data)
{
GsDebug *debug = GS_DEBUG (user_data);
+ const gchar *domains = NULL;
+ const gchar *gs_debug = NULL;
const gchar *log_domain = NULL;
const gchar *log_message = NULL;
g_autofree gchar *tmp = NULL;
g_autoptr(GMutexLocker) locker = NULL;
g_autoptr(GString) domain = NULL;
- /* enabled */
- if (g_getenv ("GS_DEBUG") == NULL &&
- log_level == G_LOG_LEVEL_DEBUG)
+ domains = g_getenv ("G_MESSAGES_DEBUG");
+ gs_debug = g_getenv ("GS_DEBUG");
+
+ /* check enabled, fast path without parsing fields */
+ if ((log_level == G_LOG_LEVEL_DEBUG ||
+ log_level == G_LOG_LEVEL_INFO) &&
+ gs_debug == NULL &&
+ (domains == NULL || *domains == '\0'))
return G_LOG_WRITER_HANDLED;
/* get data from arguments */
@@ -53,6 +60,15 @@ gs_log_writer_console (GLogLevelFlags log_level,
}
}
+ /* check enabled, slower path */
+ if ((log_level == G_LOG_LEVEL_DEBUG ||
+ log_level == G_LOG_LEVEL_INFO) &&
+ gs_debug == NULL &&
+ domains != NULL &&
+ g_strcmp0 (domains, "all") != 0 &&
+ (log_domain == NULL || !strstr (domains, log_domain)))
+ return G_LOG_WRITER_HANDLED;
+
/* this is really verbose */
if ((g_strcmp0 (log_domain, "dconf") == 0 ||
g_strcmp0 (log_domain, "GLib-GIO") == 0 ||
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]