Codebase list libvirt / bbe7743
respect log priority for qemu domain logs Closes: #524145 Guido Günther 15 years ago
2 changed file(s) with 110 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
1 Date: Thu, 16 Apr 2009 14:08:33 +0200
2 Subject: [PATCH] only log qemu monitor commands if default log priority is VIR_LOG_DEBUG
3
4 ---
5 src/libvirt_debug.syms | 1 +
6 src/logging.c | 9 +++++++++
7 src/logging.h | 2 ++
8 src/qemu_driver.c | 27 +++++++++++++++------------
9 4 files changed, 27 insertions(+), 12 deletions(-)
10
11 diff --git a/src/libvirt_debug.syms b/src/libvirt_debug.syms
12 index 1742a0b..e2e0dbd 100644
13 --- a/src/libvirt_debug.syms
14 +++ b/src/libvirt_debug.syms
15 @@ -10,6 +10,7 @@ debugFlag;
16 # logging.h
17 virLogMessage;
18 virLogSetDefaultPriority;
19 +virLogGetDefaultPriority;
20 virLogDefineFilter;
21 virLogDefineOutput;
22 virLogParseFilters;
23 diff --git a/src/logging.c b/src/logging.c
24 index 9c8b0b9..c96c8d5 100644
25 --- a/src/logging.c
26 +++ b/src/logging.c
27 @@ -326,6 +326,15 @@ int virLogSetDefaultPriority(int priority) {
28 }
29
30 /**
31 + * virLogGetDefaultPriority:
32 + *
33 + * Get the default priority level.
34 + */
35 +int virLogGetDefaultPriority() {
36 + return virLogDefaultPriority;
37 +}
38 +
39 +/**
40 * virLogResetFilters:
41 *
42 * Removes the set of logging filters defined.
43 diff --git a/src/logging.h b/src/logging.h
44 index 7ea8935..614aefb 100644
45 --- a/src/logging.h
46 +++ b/src/logging.h
47 @@ -111,6 +111,7 @@ typedef void (*virLogCloseFunc) (void *data);
48 #ifdef ENABLE_DEBUG
49
50 extern int virLogSetDefaultPriority(int priority);
51 +extern int virLogGetDefaultPriority(void);
52 extern int virLogDefineFilter(const char *match, int priority, int flags);
53 extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c,
54 void *data, int priority, int flags);
55 @@ -131,6 +132,7 @@ extern void virLogMessage(const char *category, int priority,
56 #else /* ENABLE_DEBUG */
57
58 #define virLogSetDefaultPriority(p)
59 +#define virLogGetDefaultPriority()
60 #define virLogDefineFilter(m, p, f)
61 #define virLogDefineOutput(func, c, d, p, f)
62 #define virLogStartup()
63 diff --git a/src/qemu_driver.c b/src/qemu_driver.c
64 index 79ee072..d8cd4ee 100644
65 --- a/src/qemu_driver.c
66 +++ b/src/qemu_driver.c
67 @@ -1711,25 +1711,28 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
68 }
69 }
70
71 - /* Log, but ignore failures to write logfile for VM */
72 - if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
73 - char ebuf[1024];
74 - VIR_WARN(_("Unable to log VM console data: %s\n"),
75 - virStrerror(errno, ebuf, sizeof ebuf));
76 + if (virLogGetDefaultPriority() <= VIR_LOG_DEBUG) {
77 + /* Log, but ignore failures to write logfile for VM */
78 + if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
79 + char ebuf[1024];
80 + VIR_WARN(_("Unable to log VM console data: %s\n"),
81 + virStrerror(errno, ebuf, sizeof ebuf));
82 + }
83 }
84 -
85 *reply = buf;
86 return 0;
87
88 error:
89 if (buf) {
90 - /* Log, but ignore failures to write logfile for VM */
91 - if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
92 - char ebuf[1024];
93 - VIR_WARN(_("Unable to log VM console data: %s\n"),
94 - virStrerror(errno, ebuf, sizeof ebuf));
95 + if (virLogGetDefaultPriority() <= VIR_LOG_WARN) {
96 + /* Log, but ignore failures to write logfile for VM */
97 + if (safewrite(vm->logfile, buf, strlen(buf)) < 0) {
98 + char ebuf[1024];
99 + VIR_WARN(_("Unable to log VM console data: %s\n"),
100 + virStrerror(errno, ebuf, sizeof ebuf));
101 + }
102 + VIR_FREE(buf);
103 }
104 - VIR_FREE(buf);
105 }
106 return -1;
107 }
108 --
22 0003-allow-libvirt-group-to-access-the-socket.patch
33 0004-fix-Debian-specific-path-to-hvm-loader.patch
44 0005-increase-buffer-on-ERANGE.patch
5 0006-only-log-qemu-monitor-commands-if-default-log-priori.patch