[libgsystem/wip/filetreewalk: 1/2] log: Add gs_log_with_id()



commit f418bb82d289fd613c22754fa559e7deefb1f524
Author: Colin Walters <walters verbum org>
Date:   Fri Apr 4 16:10:23 2014 -0400

    log: Add gs_log_with_id()
    
    This is useful when you want to log with a MESSAGE_ID, but not print
    to stdout.

 src/gsystem-log.c |   30 ++++++++++++++++++++++++++++++
 src/gsystem-log.h |    4 ++++
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/gsystem-log.c b/src/gsystem-log.c
index 7b03145..2b23970 100644
--- a/src/gsystem-log.c
+++ b/src/gsystem-log.c
@@ -138,6 +138,36 @@ gs_log_structured_print (const char *message,
 }
 
 /**
+ * gs_log_with_id:
+ * @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 logs the given message to the systemd journal,
+ * attaching @message_id.  If systemd is not available, the message is
+ * printed to stdout.
+ */
+void
+gs_log_with_id (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 (msg, (const char *const *)keys);
+  g_free (keys[0]);
+  g_free (msg);
+}
+
+/**
  * gs_log_structured_print_id_v:
  * @message_id: A unique MESSAGE_ID
  * @format: A format string
diff --git a/src/gsystem-log.h b/src/gsystem-log.h
index 80cfc34..43dc9e5 100644
--- a/src/gsystem-log.h
+++ b/src/gsystem-log.h
@@ -27,6 +27,10 @@ G_BEGIN_DECLS
 
 gboolean gs_stdout_is_journal (void);
 
+void gs_log_with_id (const char *message_id,
+                     const char *format,
+                     ...) G_GNUC_PRINTF (2, 3);
+
 void gs_log_structured (const char *message,
                         const char *const *keys);
 


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