summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGergely Nagy <algernon@balabit.hu>2012-03-21 14:23:35 +0100
committerGergely Nagy <algernon@balabit.hu>2012-03-21 14:23:35 +0100
commitb49beb4e96a317e9d279274dc13607dda978792c (patch)
tree9486077d17f0bd39fd480a5c9e3815c2582e0481 /lib
parent765ee19aec8a9a88c52f71336aadbc8991e8cb95 (diff)
downloadlibumberlog-b49beb4e96a317e9d279274dc13607dda978792c.tar.gz
libumberlog-b49beb4e96a317e9d279274dc13607dda978792c.tar.xz
libumberlog-b49beb4e96a317e9d279274dc13607dda978792c.zip
Add the timestamp to the JSON payload too.
Add high-precision timestamp to the JSON payload (unless disabled). Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/cee-syslog.c25
-rw-r--r--lib/cee-syslog.h1
3 files changed, 27 insertions, 1 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 99ccf47..d5c99a3 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,7 +3,7 @@ LCS_REVISION = 0
LCS_AGE = 0
lib_LTLIBRARIES = libcee-syslog.la
-libcee_syslog_la_LIBADD = @JSON_LIBS@ -ldl
+libcee_syslog_la_LIBADD = @JSON_LIBS@ -ldl -lrt
libcee_syslog_la_CFLAGS = @JSON_CFLAGS@
libcee_syslog_la_SOURCES = \
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c
index 6ad7abb..d6ae7fc 100644
--- a/lib/cee-syslog.c
+++ b/lib/cee-syslog.c
@@ -38,6 +38,7 @@
#include <string.h>
#include <syslog.h>
#include <limits.h>
+#include <time.h>
#include "cee-syslog.h"
@@ -179,6 +180,25 @@ _cee_json_append (struct json_object *json, ...)
}
static inline void
+_cee_json_append_timestamp (struct json_object *jo)
+{
+ struct timespec ts;
+ struct tm *tm;
+ char stamp[64], zone[16];
+
+ clock_gettime (CLOCK_REALTIME, &ts);
+
+ tm = localtime (&ts.tv_sec);
+
+ strftime (stamp, sizeof (stamp), "%FT%T", tm);
+ strftime (zone, sizeof (zone), "%z", tm);
+
+ _cee_json_append (jo, "timestamp", "%s.%lu%s",
+ stamp, ts.tv_nsec, zone,
+ NULL);
+}
+
+static inline void
_cee_discover (struct json_object *jo, int priority)
{
if (cee_sys_settings.flags & LOG_CEE_NODISCOVER)
@@ -193,6 +213,11 @@ _cee_discover (struct json_object *jo, int priority)
"gid", "%d", _get_gid (),
"host", "%s", _get_hostname (),
NULL);
+
+ if (cee_sys_settings.flags & LOG_CEE_NOTIME)
+ return;
+
+ _cee_json_append_timestamp (jo);
}
static struct json_object *
diff --git a/lib/cee-syslog.h b/lib/cee-syslog.h
index 70ac0cf..0725230 100644
--- a/lib/cee-syslog.h
+++ b/lib/cee-syslog.h
@@ -34,6 +34,7 @@
#define LOG_CEE_NODISCOVER 0x0040
#define LOG_CEE_NOCACHE 0x0080
#define LOG_CEE_NOCACHE_UID 0x0100
+#define LOG_CEE_NOTIME 0x0200
char *cee_format (int priority, const char *msg_format, ...);
char *cee_vformat (int priority, const char *msg_format, va_list ap);