diff options
author | Colin Walters <walters@verbum.org> | 2013-05-20 17:18:04 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-05-20 17:18:40 -0400 |
commit | 52f38c8d9bf9f4ba1ac3dea4fd1a5c89a7362191 (patch) | |
tree | 8157f5c89ced410808d440cfc46998fff0d538e9 | |
parent | daadc3cfc3e5f35e2b5f861317d23e3a4d7a2137 (diff) | |
download | libgsystem-52f38c8d9bf9f4ba1ac3dea4fd1a5c89a7362191.tar.gz |
gsystem-log: Add API to more conveniently print a message with just MESSAGE_ID
-rw-r--r-- | gsystem-log.c | 29 | ||||
-rw-r--r-- | 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 |