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

Bug#988589: cdebconf-gtk: should capture GLib structured logging to syslog in d-i



Package: cdebconf-gtk
Version: 0.257
Severity: normal
Tags: patch d-i

If a library like Pango is using the structured logging API in GLib 2.50+,
its logging messages are not caught by cdebconf-gtk's log handler.

Patch attached, also available at
<https://salsa.debian.org/installer-team/cdebconf/-/merge_requests/4>.

    smcv
>From f66ecc20da5f265cecf361f6983d92670a723bf8 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Sun, 16 May 2021 13:04:08 +0100
Subject: [PATCH] gtk: Capture new-style GLib structured logging messages under
 d-i

GLib 2.50 replaced the non-machine-readable, text-based logging that
uses g_log_set_default_handler() with a more structured logging
framework inspired by systemd-journal. Each library can either use the
structured or unstructured logging framework; unstructured messages are
received by structured log handlers, but the opposite is not true.

For the purposes of this debconf frontend, the interesting libraries
include GLib and Pango (which use structured logging) and GTK 2
(which does not). As a result, GLib and Pango debug messages did not
go to the syslog in d-i; now they do.

Signed-off-by: Simon McVittie <smcv@debian.org>
---
 debian/control                |  2 +-
 src/modules/frontend/gtk/di.c | 36 ++++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/debian/control b/debian/control
index f9c59227..caf9ead8 100644
--- a/debian/control
+++ b/debian/control
@@ -8,7 +8,7 @@ Build-Depends:
  libnewt-dev,
  libtextwrap-dev (>= 0.1-5),
  libdebian-installer4-dev (>= 0.41) | libdebian-installer-dev,
- libglib2.0-dev (>= 2.31),
+ libglib2.0-dev (>= 2.50),
  libgtk2.0-dev (>= 2.24) <!pkg.cdebconf.nogtk>,
  libcairo2-dev (>= 1.8.10-3) <!pkg.cdebconf.nogtk>,
  libselinux1-dev (>= 2.3) [linux-any] | libselinux-dev [linux-any],
diff --git a/src/modules/frontend/gtk/di.c b/src/modules/frontend/gtk/di.c
index 3dc5d38c..a6cb38f1 100644
--- a/src/modules/frontend/gtk/di.c
+++ b/src/modules/frontend/gtk/di.c
@@ -142,6 +142,40 @@ static void log_glib_to_syslog(const gchar * log_domain,
     g_free(string);
 }
 
+/** Implementation of GLogFunc for the GTK+ frontend.
+ *
+ * This will log messages going through the glib log system to the standard
+ * syslog.
+ *
+ * @param log_domain the log domain of the message
+ * @param log_level the log level of the message
+ * @param message the message to process
+ * @param user_data user data, set in g_log_set_handler()
+ */
+static GLogWriterOutput log_glib_structured_to_syslog(GLogLevelFlags log_level,
+                                                      const GLogField *fields,
+                                                      gsize n_fields,
+                                                      gpointer user_data)
+{
+    const char *domain = NULL;
+    const char *message = "(no message)";
+    gsize i;
+
+    for (i = 0; i < n_fields; i++) {
+          const GLogField *field = &fields[i];
+
+          if (g_strcmp0(field->key, "MESSAGE") == 0) {
+              message = field->value;
+          }
+          else if (g_strcmp0(field->key, "GLIB_DOMAIN") == 0) {
+              domain = field->value;
+          }
+    }
+
+    log_glib_to_syslog(domain, log_level, message, NULL);
+    return G_LOG_WRITER_HANDLED;
+}
+
 /** Make the given window fullscreen.
  *
  * @param window main window
@@ -287,7 +321,7 @@ gboolean cdebconf_gtk_di_setup(struct frontend * fe)
     fe_data->di_data = di_data;
 
     (void) g_set_printerr_handler(print_to_syslog);
-    (void) g_log_set_default_handler(log_glib_to_syslog,  NULL);
+    g_log_set_writer_func(log_glib_structured_to_syslog, NULL, NULL);
 
     make_fullscreen(fe_data->window);
     set_shortcuts(fe);
-- 
2.31.1


Reply to: