aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/logger
diff options
context:
space:
mode:
Diffstat (limited to 'src/libserver/logger')
-rw-r--r--src/libserver/logger/logger.c24
-rw-r--r--src/libserver/logger/logger_console.c25
-rw-r--r--src/libserver/logger/logger_file.c25
-rw-r--r--src/libserver/logger/logger_private.h1
4 files changed, 63 insertions, 12 deletions
diff --git a/src/libserver/logger/logger.c b/src/libserver/logger/logger.c
index 0ab6c4789..0c7400ebf 100644
--- a/src/libserver/logger/logger.c
+++ b/src/libserver/logger/logger.c
@@ -999,4 +999,28 @@ rspamd_log_line_need_escape (const guchar *src, gsize srclen)
}
return n;
+}
+
+const gchar *
+rspamd_get_log_severity_string (gint level_flags)
+{
+ unsigned int bitnum;
+ static const char *level_strs[G_LOG_LEVEL_USER_SHIFT] = {
+ "", /* G_LOG_FLAG_RECURSION */
+ "", /* G_LOG_FLAG_FATAL */
+ "crit",
+ "error",
+ "warn",
+ "notice",
+ "info",
+ "debug"
+ };
+ level_flags &= ((1u << G_LOG_LEVEL_USER_SHIFT) - 1u) & ~(G_LOG_FLAG_RECURSION|G_LOG_FLAG_FATAL);
+#ifdef __GNUC__
+ /* We assume gcc >= 3 and clang >= 5 anyway */
+ bitnum = __builtin_ffs (level_flags) - 1;
+#else
+ bitnum = ffs (level_flags) - 1;
+#endif
+ return level_strs[bitnum];
} \ No newline at end of file
diff --git a/src/libserver/logger/logger_console.c b/src/libserver/logger/logger_console.c
index c7857bdfe..3e142fe27 100644
--- a/src/libserver/logger/logger_console.c
+++ b/src/libserver/logger/logger_console.c
@@ -28,6 +28,7 @@ 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;
@@ -63,6 +64,7 @@ rspamd_log_console_init (rspamd_logger_t *logger, struct rspamd_config *cfg,
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) {
@@ -224,12 +226,23 @@ rspamd_log_console_log (const gchar *module, const gchar *id,
}
else {
if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_SYSTEMD)) {
- r += rspamd_snprintf (tmpbuf + r,
- sizeof (tmpbuf) - r,
- "%s #%P(%s) ",
- timebuf,
- rspamd_log->pid,
- rspamd_log->process_type);
+ if (priv->log_severity) {
+ r += rspamd_snprintf(tmpbuf + r,
+ sizeof(tmpbuf) - r,
+ "%s [%s] #%P(%s) ",
+ timebuf,
+ rspamd_get_log_severity_string (level_flags),
+ rspamd_log->pid,
+ rspamd_log->process_type);
+ }
+ else {
+ r += rspamd_snprintf(tmpbuf + r,
+ sizeof(tmpbuf) - r,
+ "%s #%P(%s) ",
+ timebuf,
+ rspamd_log->pid,
+ rspamd_log->process_type);
+ }
} else {
r += rspamd_snprintf (tmpbuf + r,
sizeof (tmpbuf) - r,
diff --git a/src/libserver/logger/logger_file.c b/src/libserver/logger/logger_file.c
index 3d5cc148b..81c44f8e7 100644
--- a/src/libserver/logger/logger_file.c
+++ b/src/libserver/logger/logger_file.c
@@ -36,6 +36,7 @@ struct rspamd_file_logger_priv {
gboolean throttling;
gchar *log_file;
gboolean is_buffered;
+ gboolean log_severity;
time_t throttling_time;
guint32 repeats;
guint64 last_line_cksum;
@@ -360,6 +361,7 @@ rspamd_log_file_init (rspamd_logger_t *logger, struct rspamd_config *cfg,
priv->log_file = g_strdup (cfg->log_file);
}
+ priv->log_severity = (logger->flags & RSPAMD_LOG_FLAG_SEVERITY);
priv->fd = rspamd_try_open_log_fd (logger, priv, uid, gid, err);
if (priv->fd == -1) {
@@ -506,12 +508,23 @@ rspamd_log_file_log (const gchar *module, const gchar *id,
r = 0;
if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_SYSTEMD)) {
- r += rspamd_snprintf (tmpbuf + r,
- sizeof (tmpbuf) - r,
- "%s #%P(%s) ",
- timebuf,
- rspamd_log->pid,
- cptype);
+ if (priv->log_severity) {
+ r += rspamd_snprintf(tmpbuf + r,
+ sizeof(tmpbuf) - r,
+ "%s [%s] #%P(%s) ",
+ timebuf,
+ rspamd_get_log_severity_string (level_flags),
+ rspamd_log->pid,
+ cptype);
+ }
+ else {
+ r += rspamd_snprintf(tmpbuf + r,
+ sizeof(tmpbuf) - r,
+ "%s #%P(%s) ",
+ timebuf,
+ rspamd_log->pid,
+ cptype);
+ }
}
else {
r += rspamd_snprintf (tmpbuf + r,
diff --git a/src/libserver/logger/logger_private.h b/src/libserver/logger/logger_private.h
index cb06abe7c..92bdfdba7 100644
--- a/src/libserver/logger/logger_private.h
+++ b/src/libserver/logger/logger_private.h
@@ -168,6 +168,7 @@ bool rspamd_log_console_log (const gchar *module, const gchar *id,
gsize mlen,
rspamd_logger_t *rspamd_log,
gpointer arg);
+const gchar *rspamd_get_log_severity_string(gint level_flags);
static const struct rspamd_logger_funcs console_log_funcs = {
.init = rspamd_log_console_init,