Skip to content

Commit d7ee0b2

Browse files
committed
log: increase precision in log's timestamp to nanoseconds
Signed-off-by: lecaros <[email protected]>
1 parent 499ee40 commit d7ee0b2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/flb_log.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,13 @@ int flb_log_construct(struct log_message *msg, int *ret_len,
568568
int ret;
569569
int len;
570570
int total;
571-
time_t now;
572571
const char *header_color = NULL;
573572
const char *header_title = NULL;
574573
const char *bold_color = ANSI_BOLD;
575574
const char *reset_color = ANSI_RESET;
576575
struct tm result;
577576
struct tm *current;
577+
struct timespec ts;
578578

579579
switch (type) {
580580
case FLB_LOG_HELP:
@@ -620,15 +620,15 @@ int flb_log_construct(struct log_message *msg, int *ret_len,
620620
}
621621
#endif // FLB_LOG_NO_CONTROL_CHARS
622622

623-
now = time(NULL);
624-
current = localtime_r(&now, &result);
623+
clock_gettime(CLOCK_REALTIME, &ts);
624+
current = localtime_r(&ts.tv_sec, &result);
625625

626626
if (current == NULL) {
627627
return -1;
628628
}
629629

630630
len = snprintf(msg->msg, sizeof(msg->msg) - 1,
631-
"%s[%s%i/%02i/%02i %02i:%02i:%02i%s]%s [%s%5s%s] ",
631+
"%s[%s%i/%02i/%02i %02i:%02i:%02i.%03ld%s]%s [%s%5s%s] ",
632632
/* time */ /* type */
633633

634634
/* time variables */
@@ -639,6 +639,7 @@ int flb_log_construct(struct log_message *msg, int *ret_len,
639639
current->tm_hour,
640640
current->tm_min,
641641
current->tm_sec,
642+
ts.tv_nsec,
642643
bold_color, reset_color,
643644

644645
/* type format */

0 commit comments

Comments
 (0)