The virRaiseErrorFull method sends all error messages onto the
logging code. The logging code has some logic to skip emission
when no log outputs are configured which checks the virLogSource.
This will complicate later refactoring, and the check can easily
be done in the virRaiseErrorFull method instead of in the logging
code.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/util/virerror.c | 14 ++++++++++----
src/util/virlog.c | 2 +-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 820e1ad..562c871 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -709,10 +709,16 @@ 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 (virLogGetNbOutputs() > 0)
+ virLogMessage(virErrorLogPriorityFilter ? VIR_LOG_FROM_FILE :
VIR_LOG_FROM_ERROR,
+ priority,
+ filename, linenr, funcname,
+ meta, "%s", str);
errno = save_errno;
}
diff --git a/src/util/virlog.c b/src/util/virlog.c
index e9bd61b..801f259 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -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;
--
1.8.5.3