]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Print timestamps when rspamadm is started in debug mode
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 8 Oct 2018 11:21:31 +0000 (12:21 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 8 Oct 2018 11:21:31 +0000 (12:21 +0100)
src/libutil/logger.c
src/rspamadm/rspamadm.c

index f55e3529a32943ab3eacdbc960cfc6d2b4374519..610f1683d351ca3d734751c8995344255e6fc9c0 100644 (file)
@@ -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;
 
index 49242ccaf2bd9f981844a952f188a3d8e8562163..c981d243cbf9db6498c63debbdd9178d21d14e54 100644 (file)
@@ -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);