[gnome-builder] flatpak: add debug logging when running tests



commit a1b7e97e769ba2f5e3031e3be6b9ee2288ed877d
Author: Christian Hergert <chergert redhat com>
Date:   Thu Nov 18 20:50:19 2021 -0800

    flatpak: add debug logging when running tests

 src/plugins/flatpak/daemon/gnome-builder-flatpak.c | 47 +++++++++++++---------
 src/plugins/flatpak/daemon/test-flatpak.c          |  2 +
 2 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/src/plugins/flatpak/daemon/gnome-builder-flatpak.c 
b/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
index 2dad7a5ce..65b2c1629 100644
--- a/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
+++ b/src/plugins/flatpak/daemon/gnome-builder-flatpak.c
@@ -114,6 +114,18 @@ log_level_str_with_color (GLogLevelFlags log_level)
     }
 }
 
+static int read_fileno = STDIN_FILENO;
+static int write_fileno = STDOUT_FILENO;
+static char *data_dir;
+static gboolean verbose;
+static GOptionEntry main_entries[] = {
+  { "read-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &read_fileno },
+  { "write-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &write_fileno },
+  { "data-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &data_dir },
+  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose },
+  { 0 }
+};
+
 static void
 log_func (const gchar    *log_domain,
           GLogLevelFlags  flags,
@@ -125,8 +137,10 @@ log_func (const gchar    *log_domain,
   struct tm tt;
   time_t t;
   char ftime[32];
+  char *str;
+  int fd;
 
-  if (g_log_writer_default_would_drop (flags, log_domain))
+  if (!verbose && flags < G_LOG_LEVEL_MESSAGE)
     return;
 
   if (user_data)
@@ -139,25 +153,18 @@ log_func (const gchar    *log_domain,
   tt = *localtime (&t);
   strftime (ftime, sizeof (ftime), "%H:%M:%S", &tt);
 
-  g_print ("%s.%04d  %40s[% 5d]: %s: %s\n",
-           ftime,
-           (gint)((now % G_USEC_PER_SEC) / 100L),
-           log_domain,
-           log_get_thread (),
-           level,
-           message);
+  str = g_strdup_printf ("%s.%04d  %40s[% 5d]: %s: %s\n",
+                         ftime,
+                         (gint)((now % G_USEC_PER_SEC) / 100L),
+                         log_domain,
+                         log_get_thread (),
+                         level,
+                         message);
+  fd = write_fileno == STDOUT_FILENO ? STDERR_FILENO : STDOUT_FILENO;
+  write (fd, str, strlen (str));
+  g_free (str);
 }
 
-static int read_fileno = STDIN_FILENO;
-static int write_fileno = STDOUT_FILENO;
-static char *data_dir;
-static GOptionEntry main_entries[] = {
-  { "read-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &read_fileno },
-  { "write-fd", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &write_fileno },
-  { "data-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &data_dir },
-  { 0 }
-};
-
 gint
 main (gint argc,
       gchar *argv[])
@@ -171,6 +178,8 @@ main (gint argc,
   g_autoptr(GOptionContext) context = NULL;
   g_autoptr(GError) error = NULL;
 
+  g_log_set_default_handler (log_func, GINT_TO_POINTER (isatty (STDOUT_FILENO)));
+
   g_set_prgname ("gnome-builder-flatpak");
   g_set_application_name ("gnome-builder-flatpak");
 
@@ -184,8 +193,6 @@ main (gint argc,
 
   signal (SIGPIPE, SIG_IGN);
 
-  g_log_set_default_handler (log_func, GINT_TO_POINTER (isatty (STDOUT_FILENO)));
-
   context = g_option_context_new ("");
   g_option_context_add_main_entries (context, main_entries, NULL);
 
diff --git a/src/plugins/flatpak/daemon/test-flatpak.c b/src/plugins/flatpak/daemon/test-flatpak.c
index 70ce80487..b4927ac7c 100644
--- a/src/plugins/flatpak/daemon/test-flatpak.c
+++ b/src/plugins/flatpak/daemon/test-flatpak.c
@@ -236,11 +236,13 @@ main (gint argc,
 
   g_message ("Using %s for test data directory", data_dir);
 
+  g_ptr_array_add (args, (char *)"--verbose");
   g_ptr_array_add (args, (char *)"--data-dir");
   g_ptr_array_add (args, data_dir);
   g_ptr_array_add (args, NULL);
 
   launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE);
+  g_subprocess_launcher_unsetenv (launcher, "G_MESSAGES_DEBUG");
   subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *)args->pdata, &error);
 
   if (subprocess == NULL)


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