]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Log client errors in libvirtd at debug priority
authorMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 30 Nov 2010 13:10:42 +0000 (14:10 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 30 Nov 2010 14:52:30 +0000 (15:52 +0100)
This reverts commit

 Log all errors at level INFO to stop polluting syslog
 04bd0360f32ec628ecf7943b3fd1468d6eb2dde5.

and makes virRaiseErrorFull() log errors at debug priority
when called from inside libvirtd. This stops libvirtd from
polluting it's own log with client errors at error priority
that'll be reported and logged on the client side anyway.

daemon/libvirtd.c
src/libvirt_private.syms
src/util/virterror.c
src/util/virterror_internal.h

index 66f1388619e2e700986488141f0fc44407e06ced..caf51bf809e54d1968568b74319150c0893076d9 100644 (file)
@@ -3083,6 +3083,10 @@ int main(int argc, char **argv) {
         exit(EXIT_FAILURE);
     }
 
+    /* Set error logging priority to debug, so client errors don't
+     * show up as errors in the daemon log */
+    virErrorSetLogPriority(VIR_LOG_DEBUG);
+
     while (1) {
         int optidx = 0;
         int c;
index 33e52e205d667c5b2221cd728c74b52a147b242f..ef33f862680aa441b1d2e62dde2650eb28564593 100644 (file)
@@ -831,6 +831,7 @@ virAuditSend;
 # virterror_internal.h
 virDispatchError;
 virErrorMsg;
+virErrorSetLogPriority;
 virRaiseErrorFull;
 virReportErrorHelper;
 virReportOOMErrorFull;
index 83c4c9dcf0c78122ec0496de68e8237eb4309749..6e49fa2f209b5ce5931eb66a3ba0929fe0db3d0e 100644 (file)
@@ -26,6 +26,7 @@ virThreadLocal virLastErr;
 
 virErrorFunc virErrorHandler = NULL;     /* global error handler */
 void *virUserData = NULL;        /* associated data */
+static int virErrorLogPriority = -1;
 
 /*
  * Macro used to format the message as a string in virRaiseError
@@ -64,6 +65,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) {
@@ -676,6 +689,7 @@ virRaiseErrorFull(virConnectPtr conn ATTRIBUTE_UNUSED,
 {
     virErrorPtr to;
     char *str;
+    int priority;
 
     /*
      * All errors are recorded in thread local storage
@@ -703,8 +717,14 @@ 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 an explicit error log priority is set then use it, otherwise
+     * translate the error level to the log priority. This is used by libvirtd
+     * to log client errors at debug priority.
      */
-    virLogMessage(virErrorDomainName(domain), VIR_LOG_INFO,
+    priority = virErrorLogPriority == -1 ? virErrorLevelPriority(level)
+                                         : virErrorLogPriority;
+    virLogMessage(virErrorDomainName(domain), priority,
                   funcname, linenr, 1, "%s", str);
 
     /*
@@ -1319,3 +1339,9 @@ void virReportOOMErrorFull(int domcode,
                       domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
                       virerr, NULL, NULL, -1, -1, virerr, NULL);
 }
+
+void
+virErrorSetLogPriority(int priority)
+{
+    virErrorLogPriority = priority;
+}
index 601a88472f8b3cce69d30c2a2ecf0ecb526a38e6..2dd2b4aff4a9d86149ae4a61d1d4b454cac7dab6 100644 (file)
@@ -89,5 +89,6 @@ void virReportOOMErrorFull(int domcode,
 int virSetError(virErrorPtr newerr);
 void virDispatchError(virConnectPtr conn);
 const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen);
+void virErrorSetLogPriority(int priority);
 
 #endif