提交 0915053e 编写于 作者: D Daniel P. Berrange

Include error domain and code in log messages from errors

When a virError is raised, pass the error domain and code
onto the systemd journald using metadata fields.

This allows error messages to be queried by code eg

  $ journalctl LIBVIRT_CODE=43
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 c6cae570
......@@ -173,6 +173,10 @@
<dd>The line number of the file emitting the log record</dd>
<dt><code>CODE_FUNC</code></dt>
<dd>The name of the function emitting the log record</dd>
<dt><code>LIBVIRT_DOMAIN</code></dt>
<dd>The libvirt error domain (values from virErrorDomain enum), if LIBVIRT_SOURCE="error"</dd>
<dt><code>LIBVIRT_CODE</code></dt>
<dd>The libvirt error code (values from virErrorCode enum), if LIBVIRT_SOURCE="error"</dd>
</dl>
<h2>
......
......@@ -649,6 +649,11 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
virErrorPtr to;
char *str;
int priority;
virLogMetadata meta[] = {
{ .key = "LIBVIRT_DOMAIN", .s = NULL, .iv = domain },
{ .key = "LIBVIRT_CODE", .s = NULL, .iv = code },
{ .key = NULL },
};
/*
* All errors are recorded in thread local storage
......@@ -703,10 +708,11 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
priority = virErrorLevelPriority(level);
if (virErrorLogPriorityFilter)
priority = virErrorLogPriorityFilter(to, priority);
virLogMessage(virErrorLogPriorityFilter ? VIR_LOG_FROM_FILE : VIR_LOG_FROM_ERROR,
priority,
filename, linenr, funcname,
NULL, "%s", str);
meta, "%s", str);
errno = save_errno;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册