[libvirt] [PATCH 6/6] virterror: Log reported errors when only logging output is stderr

Cole Robinson crobinso at redhat.com
Thu Nov 5 18:17:47 UTC 2009


This shouldn't be necessary, as the ideal case is only a single error message
is raised before a routine exits, and it will be printed by the default
handler.

However, libvirt bugs can cause several errors to be raised over one another,
and non default error handlers (like virsh's) will hide these. And now with
the ability to temporarily disable error raising, we want to be sure that
these interim messages are logged in some way.

Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
 src/util/logging.c   |    3 ++-
 src/util/virterror.c |    9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/util/logging.c b/src/util/logging.c
index 4899de6..d2c355c 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -504,7 +504,8 @@ cleanup:
  * @priority: the priority level
  * @funcname: the function emitting the (debug) message
  * @linenr: line where the message was emitted
- * @flags: extra flags, 1 if coming from the error handler
+ * @flags: extra flags, 1 if the message shouldn't be logged to stderr
+ *         when no logging handlers are set up.
  * @fmt: the string format
  * @...: the arguments
  *
diff --git a/src/util/virterror.c b/src/util/virterror.c
index 58b3086..f4c8766 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -705,6 +705,7 @@ virRaiseErrorFull(virConnectPtr conn,
     void *userData = virUserData;
     virErrorFunc handler = virErrorHandler;
     char *str;
+    int logging_flags;
 
     /*
      * All errors are recorded in thread local storage
@@ -730,12 +731,18 @@ virRaiseErrorFull(virConnectPtr conn,
         VIR_GET_VAR_STR(fmt, str);
     }
 
+    /* Only print message to stderr if log level == DEBUG */
+    if (virLogGetDefaultPriority() == VIR_LOG_DEBUG)
+        logging_flags = 0;
+    else
+        logging_flags = 1;
+
     /*
      * Hook up the error or warning to the logging facility
      * XXXX should we include filename as 'category' instead of domain name ?
      */
     virLogMessage(virErrorDomainName(domain), virErrorLevelPriority(level),
-                  funcname, linenr, 1, "%s", str);
+                  funcname, linenr, logging_flags, "%s", str);
 
     /* Error reporting has been deliberately disabled, don't wipe out the
      * previous error, just log what was passed and return. */
-- 
1.6.5.1




More information about the libvir-list mailing list