Skip to content

Commit 501200e

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

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/flb_log.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <fluent-bit/flb_config.h>
3333
#include <fluent-bit/flb_worker.h>
3434
#include <fluent-bit/flb_mem.h>
35+
#include <fluent-bit/flb_time.h>
3536

3637
#ifdef WIN32
3738
#include <winsock.h>
@@ -571,13 +572,13 @@ int flb_log_construct(struct log_message *msg, int *ret_len,
571572
int ret;
572573
int len;
573574
int total;
574-
time_t now;
575575
const char *header_color = NULL;
576576
const char *header_title = NULL;
577577
const char *bold_color = ANSI_BOLD;
578578
const char *reset_color = ANSI_RESET;
579579
struct tm result;
580580
struct tm *current;
581+
struct flb_time now;
581582

582583
switch (type) {
583584
case FLB_LOG_HELP:
@@ -623,15 +624,15 @@ int flb_log_construct(struct log_message *msg, int *ret_len,
623624
}
624625
#endif // FLB_LOG_NO_CONTROL_CHARS
625626

626-
now = time(NULL);
627-
current = localtime_r(&now, &result);
627+
flb_time_get(&now);
628+
current = localtime_r(&now.tm.tv_sec, &result);
628629

629630
if (current == NULL) {
630631
return -1;
631632
}
632633

633634
len = snprintf(msg->msg, sizeof(msg->msg) - 1,
634-
"%s[%s%i/%02i/%02i %02i:%02i:%02i%s]%s [%s%5s%s] ",
635+
"%s[%s%i/%02i/%02i %02i:%02i:%02i.%03ld%s]%s [%s%5s%s] ",
635636
/* time */ /* type */
636637

637638
/* time variables */
@@ -642,6 +643,7 @@ int flb_log_construct(struct log_message *msg, int *ret_len,
642643
current->tm_hour,
643644
current->tm_min,
644645
current->tm_sec,
646+
now.tm.tv_nsec,
645647
bold_color, reset_color,
646648

647649
/* type format */

0 commit comments

Comments
 (0)