diff options
-rw-r--r-- | src/libutil/logger.c | 58 | ||||
-rw-r--r-- | src/rspamadm/rspamadm.c | 3 |
2 files changed, 39 insertions, 22 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; diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 49242ccaf..c981d243c 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -412,6 +412,7 @@ main (gint argc, gchar **argv, gchar **env) /* Setup logger */ if (verbose) { cfg->log_level = G_LOG_LEVEL_DEBUG; + cfg->log_flags |= RSPAMD_LOG_FLAG_USEC; } else { cfg->log_level = G_LOG_LEVEL_MESSAGE; @@ -419,7 +420,7 @@ main (gint argc, gchar **argv, gchar **env) cfg->log_type = RSPAMD_LOG_CONSOLE; /* Avoid timestamps printing */ - cfg->log_flags = RSPAMD_LOG_FLAG_RSPAMADM; + cfg->log_flags |= RSPAMD_LOG_FLAG_RSPAMADM; rspamd_set_logger (cfg, process_quark, &rspamd_main->logger, rspamd_main->server_pool); (void) rspamd_log_open (rspamd_main->logger); |