diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-08 12:21:31 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-08 12:21:31 +0100 |
commit | 0d25b3158193565a70fecb71ef85342d7cb5b669 (patch) | |
tree | b82e2b3354e1a88d70671da5963d71a6799871ec /src/libutil | |
parent | c11d32914e568ddf604596f189beca66ca7cda61 (diff) | |
download | rspamd-0d25b3158193565a70fecb71ef85342d7cb5b669.tar.gz rspamd-0d25b3158193565a70fecb71ef85342d7cb5b669.zip |
[Minor] Print timestamps when rspamadm is started in debug mode
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/logger.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c index f55e3529a..610f1683d 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -887,6 +887,28 @@ syslog_log_function (const gchar *module, const gchar *id, #endif } + +static inline void +log_time (gdouble now, rspamd_logger_t *rspamd_log, gchar *timebuf, + size_t len) +{ + time_t sec = (time_t)now; + gsize r; + struct tm tms; + + rspamd_localtime (sec, &tms); + r = strftime (timebuf, len, "%F %H:%M:%S", &tms); + + if (rspamd_log->flags & RSPAMD_LOG_FLAG_USEC) { + gchar usec_buf[16]; + + rspamd_snprintf (usec_buf, sizeof (usec_buf), "%.5f", + now - (gdouble)sec); + rspamd_snprintf (timebuf + r, len - r, + "%s", usec_buf + 1); + } +} + /** * Main file interface for logging */ @@ -901,7 +923,7 @@ file_log_function (const gchar *module, const gchar *id, gchar tmpbuf[256]; gchar *m; gdouble now; - struct tm tms; + struct iovec iov[5]; gulong r = 0, mr = 0; guint64 cksum; @@ -1044,20 +1066,7 @@ file_log_function (const gchar *module, const gchar *id, /* Format time */ if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_SYSTEMD)) { - time_t sec = now; - gsize r; - - rspamd_localtime (sec, &tms); - r = strftime (timebuf, sizeof (timebuf), "%F %H:%M:%S", &tms); - - if (rspamd_log->flags & RSPAMD_LOG_FLAG_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); - } + log_time (now, rspamd_log, timebuf, sizeof (timebuf)); } cptype = g_quark_to_string (rspamd_log->process_type); @@ -1164,17 +1173,24 @@ file_log_function (const gchar *module, const gchar *id, iov[0].iov_base = (void *) tmpbuf; iov[0].iov_len = r; - iov[1].iov_base = (void *) message; - iov[1].iov_len = mlen; - r = 2; + r = 1; } else { - iov[0].iov_base = (void *) message; - iov[0].iov_len = mlen; - r = 1; + r = 0; } + if (rspamd_log->log_level == G_LOG_LEVEL_DEBUG) { + log_time (rspamd_get_calendar_ticks (), + rspamd_log, timebuf, sizeof (timebuf)); + iov[r].iov_base = (void *) timebuf; + iov[r++].iov_len = strlen (timebuf); + iov[r].iov_base = (void *) " "; + iov[r++].iov_len = 1; + } + + iov[r].iov_base = (void *) message; + iov[r++].iov_len = mlen; iov[r].iov_base = (void *) &lf_chr; iov[r++].iov_len = 1; |