diff options
-rw-r--r-- | sysklogd/syslogd.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 0e226124a..ab50f4a28 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -64,6 +64,14 @@ | |||
64 | //config: help | 64 | //config: help |
65 | //config: Supports restricted syslogd config. See docs/syslog.conf.txt | 65 | //config: Supports restricted syslogd config. See docs/syslog.conf.txt |
66 | //config: | 66 | //config: |
67 | //config:config FEATURE_SYSLOGD_PRECISE_TIMESTAMPS | ||
68 | //config: bool "Include milliseconds in timestamps" | ||
69 | //config: default n | ||
70 | //config: depends on SYSLOGD | ||
71 | //config: help | ||
72 | //config: Includes milliseconds (HH:MM:SS.mmm) in timestamp when | ||
73 | //config: timestamps are added. | ||
74 | //config: | ||
67 | //config:config FEATURE_SYSLOGD_READ_BUFFER_SIZE | 75 | //config:config FEATURE_SYSLOGD_READ_BUFFER_SIZE |
68 | //config: int "Read buffer size in bytes" | 76 | //config: int "Read buffer size in bytes" |
69 | //config: default 256 | 77 | //config: default 256 |
@@ -276,7 +284,7 @@ struct globals { | |||
276 | /* ...then copy to parsebuf, escaping control chars */ | 284 | /* ...then copy to parsebuf, escaping control chars */ |
277 | /* (can grow x2 max) */ | 285 | /* (can grow x2 max) */ |
278 | char parsebuf[MAX_READ*2]; | 286 | char parsebuf[MAX_READ*2]; |
279 | /* ...then sprintf into printbuf, adding timestamp (15 chars), | 287 | /* ...then sprintf into printbuf, adding timestamp (15 or 19 chars), |
280 | * host (64), fac.prio (20) to the message */ | 288 | * host (64), fac.prio (20) to the message */ |
281 | /* (growth by: 15 + 64 + 20 + delims = ~110) */ | 289 | /* (growth by: 15 + 64 + 20 + delims = ~110) */ |
282 | char printbuf[MAX_READ*2 + 128]; | 290 | char printbuf[MAX_READ*2 + 128]; |
@@ -832,12 +840,24 @@ static void timestamp_and_log(int pri, char *msg, int len) | |||
832 | msg += 16; | 840 | msg += 16; |
833 | } | 841 | } |
834 | 842 | ||
843 | #if ENABLE_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS | ||
844 | if (!timestamp) { | ||
845 | struct timeval tv; | ||
846 | gettimeofday(&tv, NULL); | ||
847 | now = tv.tv_sec; | ||
848 | timestamp = ctime(&now) + 4; /* skip day of week */ | ||
849 | /* overwrite year by milliseconds, zero terminate */ | ||
850 | sprintf(timestamp + 15, ".%03u", (unsigned)tv.tv_usec / 1000u); | ||
851 | } else { | ||
852 | timestamp[15] = '\0'; | ||
853 | } | ||
854 | #else | ||
835 | if (!timestamp) { | 855 | if (!timestamp) { |
836 | time(&now); | 856 | time(&now); |
837 | timestamp = ctime(&now) + 4; /* skip day of week */ | 857 | timestamp = ctime(&now) + 4; /* skip day of week */ |
838 | } | 858 | } |
839 | |||
840 | timestamp[15] = '\0'; | 859 | timestamp[15] = '\0'; |
860 | #endif | ||
841 | 861 | ||
842 | if (option_mask32 & OPT_kmsg) { | 862 | if (option_mask32 & OPT_kmsg) { |
843 | log_to_kmsg(pri, msg); | 863 | log_to_kmsg(pri, msg); |