Skip to content

Commit

Permalink
Merge pull request #1326 from vojtechtrefny/master_libblockdev-log
Browse files Browse the repository at this point in the history
daemon: Add a logging function for libblockdev
  • Loading branch information
vojtechtrefny authored Oct 23, 2024
2 parents 6b313e8 + 45c589a commit 019c631
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 019c631

Please sign in to comment.