aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/logger/logger_console.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-10-30 15:32:35 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-10-30 15:32:35 +0000
commitbae5cd020f84fbf84cbbe446f0726287604f150a (patch)
tree0ab0f64ee5e71acb51028a858005f1636c6e85f9 /src/libserver/logger/logger_console.c
parent81412f8b22d364ae94820fb368f669dabf5d4b94 (diff)
downloadrspamd-bae5cd020f84fbf84cbbe446f0726287604f150a.tar.gz
rspamd-bae5cd020f84fbf84cbbe446f0726287604f150a.zip
[Project] Preliminary support of JSON logging
Diffstat (limited to 'src/libserver/logger/logger_console.c')
-rw-r--r--src/libserver/logger/logger_console.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/libserver/logger/logger_console.c b/src/libserver/logger/logger_console.c
index 691566ab9..9af931faf 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 {