The systemd journal accepts arbitrary user specified log
fields. These can be passed into virLogMessage via the
virLogMetadata structure. Allow upto 5 custom fields to
be reported by libvirt callers.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/util/virlog.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 32714ce..b8f539e 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -1153,7 +1153,7 @@ virLogOutputToJournald(virLogSource source,
int linenr,
const char *funcname,
const char *timestamp ATTRIBUTE_UNUSED,
- virLogMetadataPtr metadata ATTRIBUTE_UNUSED,
+ virLogMetadataPtr metadata,
unsigned int flags,
const char *rawstr,
const char *str ATTRIBUTE_UNUSED,
@@ -1172,8 +1172,11 @@ virLogOutputToJournald(virLogSource source,
* be a tmpfs, and one that is available from early boot on
* and where unprivileged users can create files. */
char path[] = "/dev/shm/journal.XXXXXX";
+ size_t nmetadata = 0;
-# define NUM_FIELDS 6
+# define NUM_FIELDS_CORE 6
+# define NUM_FIELDS_META 5
+# define NUM_FIELDS (NUM_FIELDS_CORE + NUM_FIELDS_META)
struct iovec iov[NUM_FIELDS * 5];
char iov_bufs[NUM_FIELDS][JOURNAL_BUF_SIZE];
struct journalState state;
@@ -1192,6 +1195,17 @@ virLogOutputToJournald(virLogSource source,
journalAddInt(&state, "CODE_LINE", linenr);
if (funcname)
journalAddString(&state, "CODE_FUNC", funcname);
+ if (metadata != NULL) {
+ while (metadata->key != NULL &&
+ nmetadata < NUM_FIELDS_META) {
+ if (metadata->s != NULL)
+ journalAddString(&state, metadata->key, metadata->s);
+ else
+ journalAddInt(&state, metadata->key, metadata->iv);
+ metadata++;
+ nmetadata++;
+ }
+ }
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
--
1.8.5.3