Re: [libvirt] [PATCH v2 6/8] Include error domain and code in log messages from errors

2014-02-28 Thread Eric Blake
On 02/24/2014 09:49 AM, Daniel P. Berrange wrote:
 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

Requires the user to do a reverse lookup from the header file, but as we
have declared our public error enums as stable, it's not going to
change, so this is reasonable.

 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  docs/logging.html.in | 4 
  src/util/virerror.c  | 8 +++-
  2 files changed, 11 insertions(+), 1 deletion(-)
 

ACK

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 6/8] Include error domain and code in log messages from errors

2014-02-24 Thread Daniel P. Berrange
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: Daniel P. Berrange berra...@redhat.com
---
 docs/logging.html.in | 4 
 src/util/virerror.c  | 8 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/docs/logging.html.in b/docs/logging.html.in
index 08afa5c..f8c57f8 100644
--- a/docs/logging.html.in
+++ b/docs/logging.html.in
@@ -173,6 +173,10 @@
   ddThe line number of the file emitting the log record/dd
   dtcodeCODE_FUNC/code/dt
   ddThe name of the function emitting the log record/dd
+  dtcodeLIBVIRT_DOMAIN/code/dt
+  ddThe libvirt error domain (values from virErrorDomain enum), if 
LIBVIRT_SOURCE=error/dd
+  dtcodeLIBVIRT_CODE/code/dt
+  ddThe libvirt error code (values from virErrorCode enum), if 
LIBVIRT_SOURCE=error/dd
 /dl
 
 h2
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 74c6807..820e1ad 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -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;
 }
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list