Skip to content

Commit

Permalink
daemon: Add a logging function for libblockdev
Browse files Browse the repository at this point in the history
So we can redirect important messages from libblockdev to our log.
  • Loading branch information
vojtechtrefny committed Oct 23, 2024
1 parent 2610baa commit 45c589a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/udisksdaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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]);
Expand Down

0 comments on commit 45c589a

Please sign in to comment.