Debian Codegraph @

src/plugins/dm_logging.c

raw
1 /*
2 * Copyright (C) 2019 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * Author: Vojtech Trefny <[email protected]>
18 */
19
20 #include <glib/gprintf.h>
21 #include <syslog.h>
22 #include <stdarg.h>
23 #include <errno.h>
24 #include <blockdev/utils.h>
25
26 #include "dm_logging.h"
27
28 G_GNUC_INTERNAL void
29 redirect_dm_log (int level, const char *file G_GNUC_UNUSED, int line G_GNUC_UNUSED,
30 int dm_errno_or_class G_GNUC_UNUSED, const char *f, ...) {
31 gchar *dm_msg = NULL;
32 gchar *message = NULL;
33 gint ret = 0;
34 va_list args;
35
36 va_start (args, f);
37 ret = g_vasprintf (&dm_msg, f, args);
38 va_end (args);
39
40 if (ret < 0) {
41 g_free (dm_msg);
42 return;
43 }
44
45
46 #ifdef DEBUG
47 message = g_strdup_printf ("[libdevmapper] %s:%d %s", file, line, dm_msg);
48 #else
49 message = g_strdup_printf ("[libdevmapper] %s", dm_msg);
50 #endif
51
52 /* libdevmapper has some custom special log levels, these should be
53 internal, but just to be sure mark everything weird as debug */
54 if (level > LOG_DEBUG)
55 level = LOG_DEBUG;
56
57 bd_utils_log (level, message);
58
59 g_free (dm_msg);
60 g_free (message);
61
62 }