提交 3887c5d8 编写于 作者: D Daniel P. Berrange

Refactor code that skips logging of error messages

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: NDaniel P. Berrange <berrange@redhat.com>
上级 27f2edf9
......@@ -710,7 +710,16 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
if (virErrorLogPriorityFilter)
priority = virErrorLogPriorityFilter(to, priority);
virLogMessage(virErrorLogPriorityFilter ? VIR_LOG_FROM_FILE : VIR_LOG_FROM_ERROR,
/* 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);
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册