This reverts commit
Log all errors at level INFO to stop polluting syslog
04bd0360f32ec628ecf7943b3fd1468d6eb2dde5.
and makes virRaiseErrorFull() only log errors when not inside
libvirtd. This stops libvirtd from polluting it's own log with
client errors that'll be reported and logged on the client
side anyway.
---
daemon/libvirtd.c | 2 ++
src/libvirt_private.syms | 2 ++
src/util/logging.c | 14 ++++++++++++++
src/util/logging.h | 4 ++++
src/util/virterror.c | 22 ++++++++++++++++++++--
5 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 66f1388..0b75624 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -3083,6 +3083,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ virLogSetDaemonMode(true);
+
while (1) {
int optidx = 0;
int c;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0547cdf..a148620 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -485,6 +485,7 @@ virRegisterStorageDriver;
# logging.h
virLogDefineFilter;
virLogDefineOutput;
+virLogGetDaemonMode;
virLogGetDefaultPriority;
virLogGetFilters;
virLogGetNbFilters;
@@ -496,6 +497,7 @@ virLogParseDefaultPriority;
virLogParseFilters;
virLogParseOutputs;
virLogReset;
+virLogSetDaemonMode;
virLogSetDefaultPriority;
virLogSetFromEnv;
virLogShutdown;
diff --git a/src/util/logging.c b/src/util/logging.c
index d65dec0..e87ed6a 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -170,6 +170,7 @@ static const char *virLogPriorityString(virLogPriority lvl) {
}
static int virLogInitialized = 0;
+static bool virLogDaemonMode = false;
/**
* virLogStartup:
@@ -589,6 +590,19 @@ void virLogMessage(const char *category, int priority, const char
*funcname,
VIR_FREE(msg);
}
+bool
+virLogGetDaemonMode(void)
+{
+ return virLogDaemonMode;
+}
+
+void
+virLogSetDaemonMode(bool daemonMode)
+{
+ virLogDaemonMode = daemonMode;
+}
+
+
static int virLogOutputToFd(const char *category ATTRIBUTE_UNUSED,
int priority ATTRIBUTE_UNUSED,
const char *funcname ATTRIBUTE_UNUSED,
diff --git a/src/util/logging.h b/src/util/logging.h
index 574f68d..ef78e97 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -22,6 +22,8 @@
#ifndef __VIRTLOG_H_
# define __VIRTLOG_H_
+# include <stdbool.h>
+
# include "internal.h"
# include "buf.h"
@@ -139,5 +141,7 @@ extern int virLogParseOutputs(const char *output);
extern void virLogMessage(const char *category, int priority,
const char *funcname, long long linenr, int flags,
const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
+extern bool virLogGetDaemonMode(void);
+extern void virLogSetDaemonMode(bool daemonMode);
#endif
diff --git a/src/util/virterror.c b/src/util/virterror.c
index 83c4c9d..14d92fd 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -64,6 +64,18 @@ void *virUserData = NULL; /* associated data */
}} \
}
+static virLogPriority virErrorLevelPriority(virErrorLevel level) {
+ switch (level) {
+ case VIR_ERR_NONE:
+ return(VIR_LOG_INFO);
+ case VIR_ERR_WARNING:
+ return(VIR_LOG_WARN);
+ case VIR_ERR_ERROR:
+ return(VIR_LOG_ERROR);
+ }
+ return(VIR_LOG_ERROR);
+}
+
static const char *virErrorDomainName(virErrorDomain domain) {
const char *dom = "unknown";
switch (domain) {
@@ -703,9 +715,15 @@ virRaiseErrorFull(virConnectPtr conn ATTRIBUTE_UNUSED,
/*
* Hook up the error or warning to the logging facility
* XXXX should we include filename as 'category' instead of domain name ?
+ *
+ * When inside libvirtd don't log errors, this would pollute the syslog
+ * with client errors. Those will get reported and logged on the client
+ * side anyway.
*/
- virLogMessage(virErrorDomainName(domain), VIR_LOG_INFO,
- funcname, linenr, 1, "%s", str);
+ if (!virLogGetDaemonMode()) {
+ virLogMessage(virErrorDomainName(domain), virErrorLevelPriority(level),
+ funcname, linenr, 1, "%s", str);
+ }
/*
* Save the information about the error
--
1.7.0.4