From: Vsevolod Stakhov Date: Tue, 22 Mar 2016 09:38:33 +0000 (+0000) Subject: [Feature] Allow symbols params to be printed in logs X-Git-Tag: 1.2.1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90bf870bd8d112e8317c9b2a38782a7a6666bbac;p=rspamd.git [Feature] Allow symbols params to be printed in logs --- diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index a4e7d966c..6502f37b2 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -210,7 +210,8 @@ enum rspamd_log_format_flags { RSPAMD_LOG_FLAG_OPTIONAL = (1 << 0), RSPAMD_LOG_FLAG_MIME_ALTERNATIVE = (1 << 1), RSPAMD_LOG_FLAG_CONDITION = (1 << 2), - RSPAMD_LOG_FLAG_SYMBOLS_SCORES = (1 << 3) + RSPAMD_LOG_FLAG_SYMBOLS_SCORES = (1 << 3), + RSPAMD_LOG_FLAG_SYMBOLS_PARAMS = (1 << 4) }; struct rspamd_log_format { diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index c710cb40e..5e49d3a3d 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -346,6 +346,14 @@ rspamd_config_process_var (struct rspamd_config *cfg, const rspamd_ftok_t *var, type = RSPAMD_LOG_SYMBOLS; flags |= RSPAMD_LOG_FLAG_SYMBOLS_SCORES; } + else if (rspamd_ftok_cstr_equal (&tok, "symbols_params", TRUE)) { + type = RSPAMD_LOG_SYMBOLS; + flags |= RSPAMD_LOG_FLAG_SYMBOLS_PARAMS; + } + else if (rspamd_ftok_cstr_equal (&tok, "symbols_scores_params", TRUE)) { + type = RSPAMD_LOG_SYMBOLS; + flags |= RSPAMD_LOG_FLAG_SYMBOLS_PARAMS|RSPAMD_LOG_FLAG_SYMBOLS_SCORES; + } else if (rspamd_ftok_cstr_equal (&tok, "ip", TRUE)) { type = RSPAMD_LOG_IP; } diff --git a/src/libserver/task.c b/src/libserver/task.c index b26cc9d3c..cf26655f1 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -832,24 +832,29 @@ rspamd_task_log_metric_res (struct rspamd_task *task, sym = (struct symbol *) v; if (first) { - if (lf->flags & RSPAMD_LOG_FLAG_SYMBOLS_SCORES) { - rspamd_printf_fstring (&symbuf, "%s(%.2f)", sym->name, - sym->score); - } - else { - rspamd_printf_fstring (&symbuf, "%s", sym->name); - } - first = FALSE; + rspamd_printf_fstring (&symbuf, "%s", sym->name); } else { - if (lf->flags & RSPAMD_LOG_FLAG_SYMBOLS_SCORES) { - rspamd_printf_fstring (&symbuf, ",%s(%.2f)", sym->name, - sym->score); - } - else { - rspamd_printf_fstring (&symbuf, ",%s", sym->name); + rspamd_printf_fstring (&symbuf, ",%s", sym->name); + } + + if (lf->flags & RSPAMD_LOG_FLAG_SYMBOLS_SCORES) { + rspamd_printf_fstring (&symbuf, "(%.2f)", sym->score); + } + + if (lf->flags & RSPAMD_LOG_FLAG_SYMBOLS_PARAMS) { + GList *cur; + + rspamd_printf_fstring (&symbuf, "{"); + + for (cur = sym->options; cur != NULL; cur = g_list_next (cur)) { + rspamd_printf_fstring (&symbuf, "%s;", cur->data); } + + rspamd_printf_fstring (&symbuf, "}"); } + + first = FALSE; } rspamd_mempool_add_destructor (task->task_pool,