commit bfe48b6: [Fix] Fix logging for rspamadm
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Jan 6 19:21:06 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-01-06 19:18:40 +0000
URL: https://github.com/rspamd/rspamd/commit/bfe48b659baf0e5007e5fd6b7804881cb92e32fe (HEAD -> master)
[Fix] Fix logging for rspamadm
---
src/libserver/logger.h | 2 +-
src/libserver/logger/logger.c | 32 ++++++++++++++++++--------------
src/rspamadm/rspamadm.c | 9 ++++-----
src/rspamd.c | 2 +-
test/rspamd_test_suite.c | 9 +++++----
5 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/libserver/logger.h b/src/libserver/logger.h
index ca910c261..9bf7015c0 100644
--- a/src/libserver/logger.h
+++ b/src/libserver/logger.h
@@ -68,7 +68,7 @@ struct rspamd_logger_funcs {
* This logger is also used as an emergency logger
* @return new rspamd logger object
*/
-rspamd_logger_t * rspamd_log_open_emergency (rspamd_mempool_t *pool);
+rspamd_logger_t * rspamd_log_open_emergency (rspamd_mempool_t *pool, gint flags);
/**
* Open specific (configured logging)
diff --git a/src/libserver/logger/logger.c b/src/libserver/logger/logger.c
index fee4477a5..cf8ad496f 100644
--- a/src/libserver/logger/logger.c
+++ b/src/libserver/logger/logger.c
@@ -131,7 +131,7 @@ rspamd_emergency_logger_dtor (gpointer d)
}
rspamd_logger_t *
-rspamd_log_open_emergency (rspamd_mempool_t *pool)
+rspamd_log_open_emergency (rspamd_mempool_t *pool, gint flags)
{
rspamd_logger_t *logger;
GError *err = NULL;
@@ -147,7 +147,7 @@ rspamd_log_open_emergency (rspamd_mempool_t *pool)
logger = g_malloc0 (sizeof (rspamd_logger_t));
}
-
+ logger->flags = flags;
logger->pool = pool;
logger->process_type = "main";
@@ -432,13 +432,15 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags,
if (level >= G_LOG_LEVEL_INFO) {
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
- if ((nescaped = rspamd_log_line_need_escape (logbuf, end - logbuf)) != 0) {
- gsize unsecaped_len = end - logbuf;
- gchar *logbuf_escaped = g_alloca (unsecaped_len + nescaped * 4);
- log_line = logbuf_escaped;
+ if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM)) {
+ if ((nescaped = rspamd_log_line_need_escape (logbuf, end - logbuf)) != 0) {
+ gsize unsecaped_len = end - logbuf;
+ gchar *logbuf_escaped = g_alloca (unsecaped_len + nescaped * 4);
+ log_line = logbuf_escaped;
- end = rspamd_log_line_hex_escape (logbuf, unsecaped_len,
- logbuf_escaped,unsecaped_len + nescaped * 4);
+ end = rspamd_log_line_hex_escape (logbuf, unsecaped_len,
+ logbuf_escaped, unsecaped_len + nescaped * 4);
+ }
}
rspamd_fprintf (stderr, "%*s\n", (gint)(end - log_line),
@@ -456,13 +458,15 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags,
if (rspamd_logger_need_log (rspamd_log, level_flags, mod_id)) {
end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
- if ((nescaped = rspamd_log_line_need_escape (logbuf, end - logbuf)) != 0) {
- gsize unsecaped_len = end - logbuf;
- gchar *logbuf_escaped = g_alloca (unsecaped_len + nescaped * 4);
- log_line = logbuf_escaped;
+ if (!(rspamd_log->flags & RSPAMD_LOG_FLAG_RSPAMADM)) {
+ if ((nescaped = rspamd_log_line_need_escape (logbuf, end - logbuf)) != 0) {
+ gsize unsecaped_len = end - logbuf;
+ gchar *logbuf_escaped = g_alloca (unsecaped_len + nescaped * 4);
+ log_line = logbuf_escaped;
- end = rspamd_log_line_hex_escape (logbuf, unsecaped_len,
- logbuf_escaped,unsecaped_len + nescaped * 4);
+ end = rspamd_log_line_hex_escape (logbuf, unsecaped_len,
+ logbuf_escaped, unsecaped_len + nescaped * 4);
+ }
}
if ((level_flags & RSPAMD_LOG_ENCRYPTED) && rspamd_log->pk) {
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c
index 5de5e677a..94fa4881d 100644
--- a/src/rspamadm/rspamadm.c
+++ b/src/rspamadm/rspamadm.c
@@ -438,18 +438,17 @@ main (gint argc, gchar **argv, gchar **env)
exit (1);
}
- /* Setup logger */
- rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool);
/* Setup logger */
if (verbose) {
- rspamd_log_set_log_level (rspamd_main->logger, G_LOG_LEVEL_DEBUG);
- rspamd_log_set_log_flags (rspamd_main->logger,
+ rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool,
RSPAMD_LOG_FLAG_USEC|RSPAMD_LOG_FLAG_ENFORCED|RSPAMD_LOG_FLAG_RSPAMADM);
+ rspamd_log_set_log_level (rspamd_main->logger, G_LOG_LEVEL_DEBUG);
}
else {
+ rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool,
+ RSPAMD_LOG_FLAG_RSPAMADM);
rspamd_log_set_log_level (rspamd_main->logger, G_LOG_LEVEL_MESSAGE);
- rspamd_log_set_log_flags (rspamd_main->logger,RSPAMD_LOG_FLAG_RSPAMADM);
}
rspamd_main->event_loop = ev_default_loop (EVFLAG_SIGNALFD|EVBACKEND_ALL);
diff --git a/src/rspamd.c b/src/rspamd.c
index fce081b1c..cfaba54d6 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -1395,7 +1395,7 @@ main (gint argc, gchar **argv, gchar **env)
type = g_quark_from_static_string ("main");
/* First set logger to console logger */
- rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool);
+ rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool, 0);
g_assert (rspamd_main->logger != NULL);
if (is_debug) {
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index 4525f8ebc..7d0136708 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -52,17 +52,18 @@ main (int argc, char **argv)
}
/* Setup logger */
- rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool);
/* Setup logger */
if (verbose || g_test_verbose ()) {
- rspamd_log_set_log_level (rspamd_main->logger, G_LOG_LEVEL_DEBUG);
- rspamd_log_set_log_flags (rspamd_main->logger,
+ rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool,
RSPAMD_LOG_FLAG_USEC|RSPAMD_LOG_FLAG_ENFORCED|RSPAMD_LOG_FLAG_RSPAMADM);
+
+ rspamd_log_set_log_level (rspamd_main->logger, G_LOG_LEVEL_DEBUG);
}
else {
+ rspamd_main->logger = rspamd_log_open_emergency (rspamd_main->server_pool,
+ RSPAMD_LOG_FLAG_RSPAMADM);
rspamd_log_set_log_level (rspamd_main->logger, G_LOG_LEVEL_MESSAGE);
- rspamd_log_set_log_flags (rspamd_main->logger,RSPAMD_LOG_FLAG_RSPAMADM);
}
rspamd_lua_set_path ((lua_State *)cfg->lua_state, NULL, NULL);
More information about the Commits
mailing list