Skip to content

Commit 4d0149b

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

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

Diff for: src/flb_log.c

+6-22
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 FLB_HAVE_AWS_ERROR_REPORTER
3738
#include <fluent-bit/aws/flb_aws_error_reporter.h>
@@ -41,6 +42,8 @@ extern struct flb_aws_error_reporter *error_reporter;
4142

4243
FLB_TLS_DEFINE(struct flb_log, flb_log_ctx)
4344

45+
#define NANOSECONDS_IN_SECOND 1000000000
46+
4447
/* Simple structure to dispatch messages to the log collector */
4548
struct log_message {
4649
size_t size;
@@ -561,31 +564,12 @@ struct flb_log *flb_log_create(struct flb_config *config, int type,
561564
return log;
562565
}
563566

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

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

0 commit comments

Comments
 (0)