[libgsystem] gsystem-log: Add API to more conveniently print a message with just MESSAGE_ID



commit 52f38c8d9bf9f4ba1ac3dea4fd1a5c89a7362191
Author: Colin Walters <walters verbum org>
Date:   Mon May 20 17:18:04 2013 -0400

    gsystem-log: Add API to more conveniently print a message with just MESSAGE_ID

 gsystem-log.c |   29 +++++++++++++++++++++++++++++
 gsystem-log.h |    4 ++++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/gsystem-log.c b/gsystem-log.c
index 134fce8..0b93382 100644
--- a/gsystem-log.c
+++ b/gsystem-log.c
@@ -123,3 +123,32 @@ gs_log_structured_print (const char *message,
     g_print ("%s\n", message);
 #endif
 }
+
+/**
+ * gs_log_structured_print_id_v:
+ * @message_id: A unique MESSAGE_ID
+ * @format: A format string
+ *
+ * The provided @message_id is a unique MESSAGE_ID (see <ulink 
url="http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html";> for more information).
+ *
+ * This function otherwise acts as gs_log_structured_print(), taking
+ * @format as a format string.
+ */
+void
+gs_log_structured_print_id_v (const char *message_id,
+                              const char *format,
+                              ...)
+{
+  char *keys[] = { NULL, NULL };
+  char *msg;
+  va_list args;
+
+  va_start (args, format);
+  msg = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  keys[0] = g_strconcat ("MESSAGE_ID=", message_id, NULL);
+  gs_log_structured_print (msg, (const char *const *)keys);
+  g_free (keys[0]);
+  g_free (msg);
+}
diff --git a/gsystem-log.h b/gsystem-log.h
index 36f6f57..b7cd009 100644
--- a/gsystem-log.h
+++ b/gsystem-log.h
@@ -31,6 +31,10 @@ void gs_log_structured (const char *message,
 void gs_log_structured_print (const char *message,
                               const char *const *keys);
 
+void gs_log_structured_print_id_v (const char *message_id,
+                                   const char *format,
+                                   ...) G_GNUC_PRINTF (2, 3);
+
 G_END_DECLS
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]