Skip to content

Commit 2216177

Browse files
committed
log: use cfl_time_now to get current time
Signed-off-by: lecaros <[email protected]>
1 parent 63c67cf commit 2216177

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

src/flb_log.c

Lines changed: 6 additions & 22 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 "cfl/cfl_time.h"
3536

3637
#ifdef WIN32
3738
#include <winsock.h>
@@ -46,6 +47,8 @@ extern struct flb_aws_error_reporter *error_reporter;
4647

4748
FLB_TLS_DEFINE(struct flb_log, flb_log_ctx)
4849

50+
#define NANOSECONDS_IN_SECOND 1000000000
51+
4952
/* Simple structure to dispatch messages to the log collector */
5053
struct log_message {
5154
size_t size;
@@ -564,31 +567,12 @@ struct flb_log *flb_log_create(struct flb_config *config, int type,
564567
return log;
565568
}
566569

567-
#ifdef _WIN32
568-
#include "windows.h"
569-
570-
#define WINDOWS_EPOCH_OFFSET 116444736000000000ULL
571-
572570
void get_current_time(struct timespec *ts)
573571
{
574-
FILETIME ft;
575-
ULARGE_INTEGER li;
576-
577-
GetSystemTimeAsFileTime(&ft);
578-
li.LowPart = ft.dwLowDateTime;
579-
li.HighPart = ft.dwHighDateTime;
580-
581-
// Convert to Unix epoch
582-
uint64_t time = (li.QuadPart - WINDOWS_EPOCH_OFFSET) / 10;
583-
ts->tv_sec = time / 1000000;
584-
ts->tv_nsec = (time % 1000000) * 1000;
572+
uint64_t now = cfl_time_now();
573+
ts->tv_sec = now / NANOSECONDS_IN_SECOND;
574+
ts->tv_nsec = now % NANOSECONDS_IN_SECOND;
585575
}
586-
#else
587-
void get_current_time(struct timespec *ts)
588-
{
589-
clock_gettime(CLOCK_REALTIME, ts);
590-
}
591-
#endif
592576

593577
int flb_log_construct(struct log_message *msg, int *ret_len,
594578
int type, const char *file, int line, const char *fmt, va_list *args)

0 commit comments

Comments
 (0)