From 45c589a784a743a7008a6fafa624dff77c3fdab9 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 22 Oct 2024 14:23:28 +0200 Subject: [PATCH] daemon: Add a logging function for libblockdev So we can redirect important messages from libblockdev to our log. --- src/udisksdaemon.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/udisksdaemon.c b/src/udisksdaemon.c index 8bd58b294..d7505d8b1 100644 --- a/src/udisksdaemon.c +++ b/src/udisksdaemon.c @@ -310,6 +310,34 @@ check_modules_state_in_idle_cb (gpointer user_data) return G_SOURCE_REMOVE; } +static void +bd_log_redirect (gint level, const gchar *msg) +{ + switch (level) + { + case BD_UTILS_LOG_EMERG: + case BD_UTILS_LOG_ALERT: + case BD_UTILS_LOG_CRIT: + case BD_UTILS_LOG_ERR: + udisks_critical ("[blockdev] %s", msg); + break; + case BD_UTILS_LOG_WARNING: + udisks_warning ("[blockdev] %s", msg); + break; + case BD_UTILS_LOG_NOTICE: + udisks_notice ("[blockdev] %s", msg); + break; + case BD_UTILS_LOG_INFO: + udisks_info ("[blockdev] %s", msg); + break; + case BD_UTILS_LOG_DEBUG: + udisks_debug ("[blockdev] %s", msg); + break; + default: + break; + } +} + static void udisks_daemon_constructed (GObject *object) { @@ -342,7 +370,7 @@ udisks_daemon_constructed (GObject *object) BDPluginSpec **plugin_p = NULL; error = NULL; - ret = bd_try_init (plugins, NULL, NULL, &error); + ret = bd_try_init (plugins, bd_log_redirect, NULL, &error); if (!ret) { if (error) @@ -360,6 +388,12 @@ udisks_daemon_constructed (GObject *object) } } +#ifdef DEBUG + bd_utils_set_log_level(BD_UTILS_LOG_DEBUG); +#else + bd_utils_set_log_level(BD_UTILS_LOG_INFO); +#endif + /* Generate global UUID */ uuid_generate (uuid); uuid_unparse (uuid, &uuid_buf[0]);