summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2012-07-24 12:57:09 +0200
committerMiloslav Trmač <mitr@redhat.com>2012-07-30 07:28:36 +0200
commit806e452f28c55ee08d5a433978967fb20de02d31 (patch)
treef781654115123d11a1c74ee47f9afb00e4d31e6f /lib
parent410e2d500152ed176ba8695fb9a938b0b9bfb545 (diff)
downloadlibumberlog-806e452f28c55ee08d5a433978967fb20de02d31.tar.gz
libumberlog-806e452f28c55ee08d5a433978967fb20de02d31.tar.xz
libumberlog-806e452f28c55ee08d5a433978967fb20de02d31.zip
Default ident (log tag) to program_invocation_short_name
This is a glibc variable, so leave the "program" field missing on platforms that don't support it. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/umberlog.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/umberlog.c b/lib/umberlog.c
index aa5bded..bd29c97 100644
--- a/lib/umberlog.c
+++ b/lib/umberlog.c
@@ -193,6 +193,19 @@ _get_hostname (void)
return ul_thread_data.hostname;
}
+static inline const char *
+_get_ident (void)
+{
+ const char *ident;
+
+ ident = ul_process_data.ident;
+#ifdef HAVE_PROGRAM_INVOCATION_SHORT_NAME
+ if (ident == NULL)
+ ident = program_invocation_short_name;
+#endif
+ return ident;
+}
+
#ifdef HAVE_PARSE_PRINTF_FORMAT
#define _ul_va_spin _ul_va_spin_glibc
@@ -485,6 +498,8 @@ _ul_json_append_timestamp (ul_buffer_t *buffer)
static inline ul_buffer_t *
_ul_discover (ul_buffer_t *buffer, int priority)
{
+ const char *ident;
+
if (ul_thread_data.flags & LOG_UL_NODISCOVER)
return buffer;
@@ -499,9 +514,9 @@ _ul_discover (ul_buffer_t *buffer, int priority)
if (buffer == NULL)
return buffer;
- if (ul_process_data.ident != NULL)
- buffer = _ul_json_append (buffer, "program", "%s", ul_process_data.ident,
- NULL);
+ ident = _get_ident ();
+ if (ident != NULL)
+ buffer = _ul_json_append (buffer, "program", "%s", ident, NULL);
if (ul_thread_data.flags & LOG_UL_NOTIME || !buffer)
return buffer;