[gnome-software: 4/9] gs-debug: Allow setting verbose mode at runtime




commit b133844746359b6b143435c488cd613a7442fd01
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Feb 18 10:37:14 2021 +0000

    gs-debug: Allow setting verbose mode at runtime
    
    Add a new function to set verbose mode, and hook it up in `gs-cmd` and
    `gs-application` to the `--verbose` command line arguments.
    
    In future, it should be possible to hook it up to a D-Bus interface
    which would allow verbose mode to be enabled dynamically at runtime.
    That might make debugging a bit easier.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-cmd.c         |  3 +--
 lib/gs-debug.c       | 20 ++++++++++++++++++++
 lib/gs-debug.h       |  2 ++
 src/gs-application.c |  3 +--
 4 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index 7254eda24..868f53e38 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -343,8 +343,7 @@ main (int argc, char **argv)
                g_print ("Failed to parse options: %s\n", error->message);
                return EXIT_FAILURE;
        }
-       if (verbose)
-               g_setenv ("GS_DEBUG", "1", TRUE);
+       gs_debug_set_verbose (debug, verbose);
 
        /* prefer local sources */
        if (prefer_local)
diff --git a/lib/gs-debug.c b/lib/gs-debug.c
index 69a763eae..e3241af89 100644
--- a/lib/gs-debug.c
+++ b/lib/gs-debug.c
@@ -255,3 +255,23 @@ gs_debug_new_from_environment (void)
 
        return gs_debug_new (g_steal_pointer (&domains), verbose, use_time);
 }
+
+/**
+ * gs_debug_set_verbose:
+ * @self: a #GsDebug
+ * @verbose: whether to output log debug messages
+ *
+ * Enable or disable verbose logging mode.
+ *
+ * This can be called at any time, from any thread.
+ *
+ * Since: 40
+ */
+void
+gs_debug_set_verbose (GsDebug  *self,
+                      gboolean  verbose)
+{
+       g_return_if_fail (GS_IS_DEBUG (self));
+
+       g_atomic_int_set (&self->verbose, verbose);
+}
diff --git a/lib/gs-debug.h b/lib/gs-debug.h
index 2abbe9303..d927f816d 100644
--- a/lib/gs-debug.h
+++ b/lib/gs-debug.h
@@ -21,5 +21,7 @@ GsDebug               *gs_debug_new           (gchar          **domains,
                                         gboolean         verbose,
                                         gboolean         use_time);
 GsDebug                *gs_debug_new_from_environment  (void);
+void            gs_debug_set_verbose   (GsDebug        *self,
+                                        gboolean        verbose);
 
 G_END_DECLS
diff --git a/src/gs-application.c b/src/gs-application.c
index 88af2d470..0117a4e0d 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -1121,8 +1121,7 @@ gs_application_handle_local_options (GApplication *app, GVariantDict *options)
        gint rc = -1;
        g_autoptr(GError) error = NULL;
 
-       if (g_variant_dict_contains (options, "verbose"))
-               g_setenv ("GS_DEBUG", "1", TRUE);
+       gs_debug_set_verbose (self->debug, g_variant_dict_contains (options, "verbose"));
 
        /* prefer local sources */
        if (g_variant_dict_contains (options, "prefer-local"))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]