Skip to content

Commit 8b1d3db

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

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/flb_log.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,11 @@ void flb_log_print(int type, const char *file, int line, const char *fmt, ...)
802802
int ret;
803803
struct log_message msg = {0};
804804
va_list args;
805+
const char *msg_type_str;
806+
uint64_t ts;
805807

806808
struct flb_worker *w;
809+
struct flb_config *config;
807810

808811
va_start(args, fmt);
809812
ret = flb_log_construct(&msg, &len, type, file, line, fmt, &args);
@@ -815,6 +818,25 @@ void flb_log_print(int type, const char *file, int line, const char *fmt, ...)
815818

816819
w = flb_worker_get();
817820
if (w) {
821+
config = w->config;
822+
if (config != NULL && config->log != NULL) {
823+
msg_type_str = flb_log_message_type_str(type);
824+
if (msg_type_str == NULL) {
825+
msg_type_str = "unknown";
826+
}
827+
828+
ts = cfl_time_now();
829+
ret = cmt_counter_inc(config->log->metrics->logs_total_counter,
830+
ts,
831+
1, (char *[]) {msg_type_str});
832+
if (ret == -1) {
833+
/* Not using flb_log_debug to avoid recursing into this same function. */
834+
fprintf(stderr,
835+
"[log] failed to increment log total counter for message type '%s' (error=%d)\n",
836+
msg_type_str, ret);
837+
}
838+
}
839+
818840
n = flb_pipe_write_all(w->log[1], &msg, sizeof(msg));
819841

820842
if (n == -1) {
@@ -874,6 +896,7 @@ int flb_log_destroy(struct flb_log *log, struct flb_config *config)
874896
}
875897
flb_log_worker_destroy(log->worker);
876898
flb_free(log->worker);
899+
flb_log_metrics_destroy(log->metrics);
877900
flb_free(log);
878901

879902
return 0;

0 commit comments

Comments
 (0)