Skip to content

Commit 45c589a

Browse files
committed
daemon: Add a logging function for libblockdev
So we can redirect important messages from libblockdev to our log.
1 parent 2610baa commit 45c589a

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/udisksdaemon.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,34 @@ check_modules_state_in_idle_cb (gpointer user_data)
310310
return G_SOURCE_REMOVE;
311311
}
312312

313+
static void
314+
bd_log_redirect (gint level, const gchar *msg)
315+
{
316+
switch (level)
317+
{
318+
case BD_UTILS_LOG_EMERG:
319+
case BD_UTILS_LOG_ALERT:
320+
case BD_UTILS_LOG_CRIT:
321+
case BD_UTILS_LOG_ERR:
322+
udisks_critical ("[blockdev] %s", msg);
323+
break;
324+
case BD_UTILS_LOG_WARNING:
325+
udisks_warning ("[blockdev] %s", msg);
326+
break;
327+
case BD_UTILS_LOG_NOTICE:
328+
udisks_notice ("[blockdev] %s", msg);
329+
break;
330+
case BD_UTILS_LOG_INFO:
331+
udisks_info ("[blockdev] %s", msg);
332+
break;
333+
case BD_UTILS_LOG_DEBUG:
334+
udisks_debug ("[blockdev] %s", msg);
335+
break;
336+
default:
337+
break;
338+
}
339+
}
340+
313341
static void
314342
udisks_daemon_constructed (GObject *object)
315343
{
@@ -342,7 +370,7 @@ udisks_daemon_constructed (GObject *object)
342370
BDPluginSpec **plugin_p = NULL;
343371
error = NULL;
344372

345-
ret = bd_try_init (plugins, NULL, NULL, &error);
373+
ret = bd_try_init (plugins, bd_log_redirect, NULL, &error);
346374
if (!ret)
347375
{
348376
if (error)
@@ -360,6 +388,12 @@ udisks_daemon_constructed (GObject *object)
360388
}
361389
}
362390

391+
#ifdef DEBUG
392+
bd_utils_set_log_level(BD_UTILS_LOG_DEBUG);
393+
#else
394+
bd_utils_set_log_level(BD_UTILS_LOG_INFO);
395+
#endif
396+
363397
/* Generate global UUID */
364398
uuid_generate (uuid);
365399
uuid_unparse (uuid, &uuid_buf[0]);

0 commit comments

Comments
 (0)