diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-08-06 17:55:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-08-06 17:55:22 +0100 |
commit | 9673734623b8972c86179b2c71ef6d2b353ee07f (patch) | |
tree | 6b60578eda2ccf700a1755c8e878b9ab8f443f56 /src/libutil | |
parent | 9632c62a868e9086c5a016eb6b259ffe6f233770 (diff) | |
download | rspamd-9673734623b8972c86179b2c71ef6d2b353ee07f.tar.gz rspamd-9673734623b8972c86179b2c71ef6d2b353ee07f.zip |
[Feature] Allow to have high precision timestamps in logs
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/logger.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c index d4e3e95a7..de301cc62 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -833,9 +833,9 @@ file_log_function (const gchar *module, const gchar *id, const gchar *message, gpointer arg) { - gchar tmpbuf[256], timebuf[32], modulebuf[64]; + gchar tmpbuf[256], timebuf[64], modulebuf[64]; gchar *m; - time_t now; + gdouble now; struct tm *tms; struct iovec iov[5]; gulong r = 0, mr = 0; @@ -851,7 +851,7 @@ file_log_function (const gchar *module, const gchar *id, /* Check throttling due to write errors */ if (!(level_flags & RSPAMD_LOG_FORCED) && rspamd_log->throttling) { - now = time (NULL); + now = rspamd_get_calendar_ticks (); if (rspamd_log->throttling_time != now) { rspamd_log->throttling_time = now; got_time = TRUE; @@ -973,14 +973,25 @@ file_log_function (const gchar *module, const gchar *id, if (rspamd_log->cfg->log_extended) { if (!got_time) { - now = time (NULL); + now = rspamd_get_calendar_ticks (); } /* Format time */ if (!rspamd_log->cfg->log_systemd) { - tms = localtime (&now); + time_t sec = now; + gsize r; - strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", tms); + tms = localtime (&sec); + r = strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", tms); + + if (rspamd_log->cfg->log_usec) { + gchar usec_buf[16]; + + rspamd_snprintf (usec_buf, sizeof (usec_buf), "%.5f", + now - (gdouble)sec); + rspamd_snprintf (timebuf + r, sizeof (timebuf) - r, + "%s", usec_buf + 1); + } } cptype = g_quark_to_string (rspamd_log->process_type); |