aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-04 16:52:15 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-04 16:52:15 +0000
commit503d1bceb2df4b88acd41455ddebf0efae9fd391 (patch)
treee2a84093a246ec3b1d643d045b35c013cfbf358e
parent7d237da3934bec416fab604af74f61e8c53f0505 (diff)
downloadrspamd-503d1bceb2df4b88acd41455ddebf0efae9fd391.tar.gz
rspamd-503d1bceb2df4b88acd41455ddebf0efae9fd391.zip
[Minor] Improve logging to console
-rw-r--r--src/libserver/cfg_file.h1
-rw-r--r--src/libutil/logger.c20
2 files changed, 13 insertions, 8 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 0aa8df36c..1cf4a1faf 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -76,6 +76,7 @@ enum rspamd_log_cfg_flags {
RSPAMD_LOG_FLAG_USEC = (1 << 3),
RSPAMD_LOG_FLAG_RSPAMADM = (1 << 4),
RSPAMD_LOG_FLAG_ENFORCED = (1 << 5),
+ RSPAMD_LOG_FLAG_TTY = (1 << 6),
};
struct rspamd_worker_log_pipe {
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index cb57b6825..31d018533 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -168,7 +168,7 @@ direct_write_log_line (rspamd_logger_t *rspamd_log,
}
}
else {
- fd = STDERR_FILENO;
+ fd = rspamd_log->fd;
}
}
else {
@@ -189,7 +189,7 @@ direct_write_log_line (rspamd_logger_t *rspamd_log,
tlen = count;
}
- if (tlen > PIPE_BUF) {
+ if (tlen > PIPE_BUF || rspamd_log->flags & RSPAMD_LOG_FLAG_TTY) {
locked = TRUE;
#ifndef DISABLE_PTHREAD_MUTEX
@@ -306,8 +306,11 @@ rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
if (!rspamd_log->opened) {
switch (rspamd_log->log_type) {
case RSPAMD_LOG_CONSOLE:
- /* Do nothing with console */
- rspamd_log->fd = -1;
+ /* Dup stderr fd to simplify processing */
+ rspamd_log->fd = dup (STDERR_FILENO);
+ if (isatty (STDERR_FILENO)) {
+ rspamd_log->flags |= RSPAMD_LOG_FLAG_TTY;
+ }
break;
case RSPAMD_LOG_SYSLOG:
#ifdef HAVE_SYSLOG_H
@@ -385,9 +388,6 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, gboolean termination, uid_t
if (rspamd_log->opened) {
switch (rspamd_log->type) {
- case RSPAMD_LOG_CONSOLE:
- /* Do nothing special */
- break;
case RSPAMD_LOG_SYSLOG:
#ifdef HAVE_SYSLOG_H
closelog ();
@@ -407,6 +407,11 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, gboolean termination, uid_t
close (rspamd_log->fd);
}
break;
+ case RSPAMD_LOG_CONSOLE:
+ if (rspamd_log->fd != -1) {
+ close (rspamd_log->fd);
+ }
+ break;
}
rspamd_log->enabled = FALSE;
@@ -522,7 +527,6 @@ rspamd_set_logger (struct rspamd_config *cfg,
switch (cfg->log_type) {
case RSPAMD_LOG_CONSOLE:
logger->log_func = file_log_function;
- logger->fd = -1;
break;
case RSPAMD_LOG_SYSLOG:
logger->log_func = syslog_log_function;