MINOR: log: add time second fraction field to rfc5424 log timestamp.
This patch adds the time second fraction in microseconds
as supported by the rfc.
diff --git a/include/haproxy/log.h b/include/haproxy/log.h
index 4fccb53..c3e1d41 100644
--- a/include/haproxy/log.h
+++ b/include/haproxy/log.h
@@ -137,7 +137,7 @@
/*
* Function to handle log header building (exported for sinks)
*/
-char *update_log_hdr_rfc5424(const time_t time);
+char *update_log_hdr_rfc5424(const time_t time, suseconds_t frac);
char *update_log_hdr(const time_t time);
char * get_format_pid_sep1(int format, size_t *len);
char * get_format_pid_sep2(int format, size_t *len);
diff --git a/src/log.c b/src/log.c
index 192525e..e65b9ca 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1483,10 +1483,11 @@
* the beginning of logheader_rfc5424 once a second and return the pointer
* to the first character after it.
*/
-char *update_log_hdr_rfc5424(const time_t time)
+char *update_log_hdr_rfc5424(const time_t time, const suseconds_t frac)
{
static THREAD_LOCAL long tvsec;
const char *gmt_offset;
+ char c;
if (unlikely(time != tvsec || logheader_rfc5424_end == NULL)) {
/* this string is rebuild only once a second */
@@ -1498,7 +1499,7 @@
gmt_offset = get_gmt_offset(time, &tm);
hdr_len = snprintf(logheader_rfc5424, global.max_syslog_len,
- "<<<<>1 %4d-%02d-%02dT%02d:%02d:%02d%.3s:%.2s %s ",
+ "<<<<>1 %4d-%02d-%02dT%02d:%02d:%02d.000000%.3s:%.2s %s ",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
gmt_offset, gmt_offset+3,
@@ -1513,6 +1514,11 @@
logheader_rfc5424_end = logheader_rfc5424 + hdr_len;
}
+ /* utoa_pad add a trailing '\0' so we save the char to restore */
+ c = logheader_rfc5424[33];
+ utoa_pad(frac, logheader_rfc5424 + 27, 7);
+ logheader_rfc5424[33] = c;
+
logheader_rfc5424_end[0] = 0; // ensure we get rid of any previous attempt
return logheader_rfc5424_end;
@@ -1629,7 +1635,7 @@
case LOG_FORMAT_RFC5424:
hdr = logheader_rfc5424;
- hdr_ptr = update_log_hdr_rfc5424(time);
+ hdr_ptr = update_log_hdr_rfc5424(time, date.tv_usec);
sd_max = sd_size; /* the SD part allowed only in RFC5424 */
break;
diff --git a/src/sink.c b/src/sink.c
index e3eac2b..19a555e 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -182,7 +182,7 @@
}
else if (sink->fmt == SINK_FMT_RFC5424) {
pfx[npfx].ptr = logheader_rfc5424;
- pfx[npfx].len = update_log_hdr_rfc5424(date.tv_sec) - pfx[npfx].ptr;
+ pfx[npfx].len = update_log_hdr_rfc5424(date.tv_sec, date.tv_usec) - pfx[npfx].ptr;
log_format = LOG_FORMAT_RFC5424;
}
else {