diff options
Diffstat (limited to 'src/libserver/logger/logger_console.c')
-rw-r--r-- | src/libserver/logger/logger_console.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/libserver/logger/logger_console.c b/src/libserver/logger/logger_console.c index 691566ab9..7f3c7708f 100644 --- a/src/libserver/logger/logger_console.c +++ b/src/libserver/logger/logger_console.c @@ -28,10 +28,6 @@ static const gchar lf_chr = '\n'; struct rspamd_console_logger_priv { gint fd; gint crit_fd; - gboolean log_severity; - gboolean log_color; - gboolean log_rspamadm; - gboolean log_tty; }; /* Copy & paste :( */ @@ -63,11 +59,8 @@ rspamd_log_console_init(rspamd_logger_t *logger, struct rspamd_config *cfg, struct rspamd_console_logger_priv *priv; priv = g_malloc0(sizeof(*priv)); - priv->log_color = (logger->flags & RSPAMD_LOG_FLAG_COLOR); - priv->log_severity = (logger->flags & RSPAMD_LOG_FLAG_SEVERITY); - priv->log_rspamadm = (logger->flags & RSPAMD_LOG_FLAG_RSPAMADM); - if (priv->log_rspamadm) { + if (logger->flags & RSPAMD_LOG_FLAG_RSPAMADM) { priv->fd = dup(STDOUT_FILENO); priv->crit_fd = dup(STDERR_FILENO); } @@ -85,12 +78,11 @@ rspamd_log_console_init(rspamd_logger_t *logger, struct rspamd_config *cfg, return NULL; } - if (isatty(priv->fd)) { - priv->log_tty = true; - } - else if (priv->log_color) { - /* Disable colors for not a tty */ - priv->log_color = false; + if (!isatty(priv->fd)) { + if (logger->flags & RSPAMD_LOG_FLAG_COLOR) { + /* Disable colors for not a tty */ + logger->flags &= ~RSPAMD_LOG_FLAG_COLOR; + } } return priv; @@ -160,7 +152,8 @@ bool rspamd_log_console_log(const gchar *module, const gchar *id, fd = priv->crit_fd; } else { - if (priv->log_rspamadm && (level_flags & G_LOG_LEVEL_WARNING)) { + /* Use stderr if we are in rspamadm mode and severity is more than WARNING */ + if ((rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM) && (level_flags & G_LOG_LEVEL_WARNING)) { fd = priv->crit_fd; } else { @@ -180,15 +173,15 @@ bool rspamd_log_console_log(const gchar *module, const gchar *id, #endif now = rspamd_get_calendar_ticks(); - gsize niov = rspamd_log_fill_iov(NULL, now, module, id, - function, level_flags, message, - mlen, rspamd_log); - struct iovec *iov = g_alloca(sizeof(struct iovec) * niov); - rspamd_log_fill_iov(iov, now, module, id, function, level_flags, message, + + struct rspamd_logger_iov_ctx iov_ctx; + memset(&iov_ctx, 0, sizeof(iov_ctx)); + rspamd_log_fill_iov(&iov_ctx, now, module, id, + function, level_flags, message, mlen, rspamd_log); again: - r = writev(fd, iov, niov); + r = writev(fd, iov_ctx.iov, iov_ctx.niov); if (r == -1) { if (errno == EAGAIN || errno == EINTR) { @@ -202,6 +195,7 @@ again: rspamd_file_unlock(fd, FALSE); } + rspamd_log_iov_free(&iov_ctx); return false; } @@ -212,5 +206,6 @@ again: rspamd_file_unlock(fd, FALSE); } + rspamd_log_iov_free(&iov_ctx); return true; }
\ No newline at end of file |