Line data Source code
1 : /*
2 : Copyright (C) 2012-2015 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 :
18 : #include <config.h>
19 :
20 : #include <glib.h>
21 : #include <stdlib.h>
22 : #include <common/recorder.h>
23 :
24 : #include "log.h"
25 : #include "backtrace.h"
26 :
27 : #define G_LOG_DOMAIN "Spice"
28 :
29 10 : SPICE_CONSTRUCTOR_FUNC(spice_log_init)
30 : {
31 10 : recorder_dump_on_common_signals(0, 0);
32 10 : }
33 :
34 : G_GNUC_PRINTF(5, 0)
35 11 : static void spice_logv(const char *log_domain,
36 : GLogLevelFlags log_level,
37 : const char *strloc,
38 : const char *function,
39 : const char *format,
40 : va_list args)
41 : {
42 : GString *log_msg;
43 :
44 11 : log_msg = g_string_new(NULL);
45 11 : if (strloc && function) {
46 11 : g_string_append_printf(log_msg, "%s:%s: ", strloc, function);
47 : }
48 11 : if (format) {
49 11 : g_string_append_vprintf(log_msg, format, args);
50 : }
51 11 : g_log(log_domain, log_level, "%s", log_msg->str);
52 11 : g_string_free(log_msg, TRUE);
53 :
54 11 : if ((log_level & G_LOG_LEVEL_CRITICAL) != 0) {
55 0 : spice_backtrace();
56 0 : abort();
57 : }
58 11 : }
59 :
60 11 : void spice_log(GLogLevelFlags log_level,
61 : const char *strloc,
62 : const char *function,
63 : const char *format,
64 : ...)
65 : {
66 : va_list args;
67 :
68 11 : va_start (args, format);
69 11 : spice_logv (G_LOG_DOMAIN, log_level, strloc, function, format, args);
70 11 : va_end (args);
71 11 : }
|