]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add filename to log format
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Mar 2018 17:58:16 +0000 (17:58 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Mar 2018 17:58:16 +0000 (17:58 +0000)
conf/logging.inc
src/libserver/cfg_file.h
src/libserver/cfg_utils.c
src/libserver/task.c

index b8d032c414161d5a21f852b6e0c4033e11a24e28..676845291815440bf7c44d5d02fba8a52f637779 100644 (file)
@@ -5,7 +5,7 @@ log_format =<<EOD
 id: <$mid>,$if_qid{ qid: <$>,}$if_ip{ ip: $,}$if_user{ user: $,}$if_smtp_from{ from: <$>,}
 (default: $is_spam ($action): [$scores] [$symbols_scores_params]),
 len: $len, time: $time_real real, $time_virtual virtual, dns req: $dns_req,
-digest: <$digest>$if_smtp_rcpts{, rcpts: <$>}$if_mime_rcpt{, mime_rcpt: <$>}
+digest: <$digest>$if_smtp_rcpts{, rcpts: <$>}$if_mime_rcpt{, mime_rcpt: <$>}$if_filename{, file: $}
 EOD
 
 
index 199c965f4ba860f5ba309c70f0a6307ec296cb7d..ede88d9d761fb1cda4d5f9a46cdbd5a8d5b9cde7 100644 (file)
@@ -234,6 +234,7 @@ enum rspamd_log_format_type {
        RSPAMD_LOG_TIME_VIRTUAL,
        RSPAMD_LOG_LUA,
        RSPAMD_LOG_DIGEST,
+       RSPAMD_LOG_FILENAME,
 };
 
 enum rspamd_log_format_flags {
index 86009712e8ab15ff169a4bde4a0585abf2cd07de..c042c5eb2074f703eef28bb3b1d5ba240cfc471c 100644 (file)
@@ -425,6 +425,9 @@ rspamd_config_process_var (struct rspamd_config *cfg, const rspamd_ftok_t *var,
                        rspamd_ftok_cstr_equal (&tok, "checksum", TRUE)) {
                type = RSPAMD_LOG_DIGEST;
        }
+       else if (rspamd_ftok_cstr_equal (&tok, "filename", TRUE)) {
+               type = RSPAMD_LOG_FILENAME;
+       }
        else {
                msg_err_config ("unknown log variable: %T", &tok);
                return FALSE;
index dfb7f07c9add479c28d63d656e760d94de8bacb2..55a00649deabab726bc8b3f118ccfbbe12d8e547 100644 (file)
@@ -986,6 +986,11 @@ rspamd_task_log_check_condition (struct rspamd_task *task,
                        ret = TRUE;
                }
                break;
+       case RSPAMD_LOG_FILENAME:
+               if (task->msg.fpath) {
+                       ret = TRUE;
+               }
+               break;
        default:
                ret = TRUE;
                break;
@@ -1268,6 +1273,7 @@ rspamd_task_log_variable (struct rspamd_task *task,
        rspamd_fstring_t *res = logbuf;
        rspamd_ftok_t var = {.begin = NULL, .len = 0};
        static gchar numbuf[64];
+       static const gchar undef[] = "undef";
 
        switch (lf->type) {
        /* String vars */
@@ -1277,8 +1283,8 @@ rspamd_task_log_variable (struct rspamd_task *task,
                        var.len = strlen (var.begin);
                }
                else {
-                       var.begin = "undef";
-                       var.len = 5;
+                       var.begin = undef;
+                       var.len = sizeof (undef) - 1;
                }
                break;
        case RSPAMD_LOG_QID:
@@ -1287,8 +1293,8 @@ rspamd_task_log_variable (struct rspamd_task *task,
                        var.len = strlen (var.begin);
                }
                else {
-                       var.begin = "undef";
-                       var.len = 5;
+                       var.begin = undef;
+                       var.len = sizeof (undef) - 1;
                }
                break;
        case RSPAMD_LOG_USER:
@@ -1297,8 +1303,8 @@ rspamd_task_log_variable (struct rspamd_task *task,
                        var.len = strlen (var.begin);
                }
                else {
-                       var.begin = "undef";
-                       var.len = 5;
+                       var.begin = undef;
+                       var.len = sizeof (undef) - 1;
                }
                break;
        case RSPAMD_LOG_IP:
@@ -1307,8 +1313,8 @@ rspamd_task_log_variable (struct rspamd_task *task,
                        var.len = strlen (var.begin);
                }
                else {
-                       var.begin = "undef";
-                       var.len = 5;
+                       var.begin = undef;
+                       var.len = sizeof (undef) - 1;
                }
                break;
        /* Numeric vars */
@@ -1376,6 +1382,16 @@ rspamd_task_log_variable (struct rspamd_task *task,
                                (gint)sizeof (task->digest), task->digest);
                var.begin = numbuf;
                break;
+       case RSPAMD_LOG_FILENAME:
+               if (task->msg.fpath) {
+                       var.len = strlen (task->msg.fpath);
+                       var.begin = task->msg.fpath;
+               }
+               else {
+                       var.begin = undef;
+                       var.len = sizeof (undef) - 1;
+               }
+               break;
        default:
                var = rspamd_task_log_metric_res (task, lf);
                break;