]> xenbits.xensource.com Git - libvirt.git/commitdiff
Refactor code that skips logging of error messages
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 3 Mar 2014 18:29:33 +0000 (18:29 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 18 Mar 2014 14:29:21 +0000 (14:29 +0000)
The error reporting code will invoke a callback when any error
is raised and the default callback will print to stderr. The
virRaiseErrorFull method also sends all error messages on to the
logging code, which also prints to stderr by default. To avoid
duplicated data on stderr, the logging code has some logic to
skip emission when no log outputs are configured, which checks
whether the virLogSource == VIR_LOG_FROM_ERROR.

Meanwhile the libvirtd daemon can register another callback which
is used to reduce log message priority from error to a lower level.
When this is used we do want messages to end up on stderr, so the
error code will conditionally use either VIR_LOG_FROM_FILE or
VIR_LOG_FROM_ERROR depending on whether such a callback is provided.

This will all complicate later refactoring. By pushing the checks
for whether a log output is present up a level into the error code,
the special cases can be isolated in one place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/util/virerror.c
src/util/virlog.c

index 3eb4f5d26753300eb03854ffe9db011f8262514e..ae303d57a526aff214d04165a202f38e87efc7e2 100644 (file)
@@ -710,10 +710,19 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
     if (virErrorLogPriorityFilter)
         priority = virErrorLogPriorityFilter(to, priority);
 
-    virLogMessage(virErrorLogPriorityFilter ? VIR_LOG_FROM_FILE : VIR_LOG_FROM_ERROR,
-                  priority,
-                  filename, linenr, funcname,
-                  meta, "%s", str);
+    /* We don't want to pollute stderr if no logging outputs
+     * are explicitly requested by the user, since the default
+     * error function already pollutes stderr and most apps
+     * hate & thus disable that too. If the daemon has set
+     * a priority filter though, we should always forward
+     * all errors to the logging code.
+     */
+    if (virLogGetNbOutputs() > 0 ||
+        virErrorLogPriorityFilter)
+        virLogMessage(VIR_LOG_FROM_ERROR,
+                      priority,
+                      filename, linenr, funcname,
+                      meta, "%s", str);
 
     errno = save_errno;
 }
index e9bd61b47183e9c68f567d673535a3e2c41a1701..801f25952ee147ed56a6d51ee07a08bf86e6d276 100644 (file)
@@ -882,7 +882,7 @@ virLogVMessage(virLogSource source,
                                str, msg, virLogOutputs[i].data);
         }
     }
-    if ((virLogNbOutputs == 0) && (source != VIR_LOG_FROM_ERROR)) {
+    if (virLogNbOutputs == 0) {
         if (logVersionStderr) {
             const char *rawver;
             char *ver = NULL;