]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix several issues with the lua_logger
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 10 Jun 2025 15:28:49 +0000 (16:28 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 10 Jun 2025 15:28:49 +0000 (16:28 +0100)
src/plugins/lua/arc.lua
src/plugins/lua/fuzzy_collect.lua
src/plugins/lua/gpt.lua
src/plugins/lua/history_redis.lua
src/plugins/lua/multimap.lua
src/plugins/lua/ratelimit.lua
src/plugins/lua/rbl.lua
src/plugins/lua/settings.lua
src/plugins/lua/spamassassin.lua
src/plugins/lua/trie.lua

index 07fb5c63fa8806f5384d1a42aff43cb137869e3c..45da1f5a265e5a2ca6a2df45b079a5c7e8e94ecd 100644 (file)
@@ -695,11 +695,11 @@ local function do_sign(task, sign_params)
           sign_params.pubkey = results[1]
           sign_params.strict_pubkey_check = not settings.allow_pubkey_mismatch
         elseif not settings.allow_pubkey_mismatch then
-          rspamd_logger.errx('public key for domain %s/%s is not found: %s, skip signing',
+          rspamd_logger.errx(task, 'public key for domain %s/%s is not found: %s, skip signing',
               sign_params.domain, sign_params.selector, err)
           return
         else
-          rspamd_logger.infox('public key for domain %s/%s is not found: %s',
+          rspamd_logger.infox(task, 'public key for domain %s/%s is not found: %s',
               sign_params.domain, sign_params.selector, err)
         end
 
index 132ace90c00214a8b4da1df29336a93593736100..060cc2fc284bb34df164389412b1d4e70910dcc9 100644 (file)
@@ -34,7 +34,7 @@ local settings = {
 local function send_data_mirror(m, cfg, ev_base, body)
   local function store_callback(err, _, _, _)
     if err then
-      rspamd_logger.errx(cfg, 'cannot save data on %(%s): %s', m.server, m.name, err)
+      rspamd_logger.errx(cfg, 'cannot save data on %s(%s): %s', m.server, m.name, err)
     else
       rspamd_logger.infox(cfg, 'saved data on %s(%s)', m.server, m.name)
     end
index 51df0bc20cc337eb43e03b29a28933d74a526d71..6fe5adb9c2f5f006cf614e1fa5b57178bbe484e7 100644 (file)
@@ -301,7 +301,7 @@ local function default_openai_json_conversion(task, input)
       elseif reply.probability == "low" then
         spam_score = 0.1
       else
-        rspamd_logger.infox("cannot convert to spam probability: %s", reply.probability)
+        rspamd_logger.infox(task, "cannot convert to spam probability: %s", reply.probability)
       end
     end
 
@@ -466,7 +466,7 @@ local function default_ollama_json_conversion(task, input)
       elseif reply.probability == "low" then
         spam_score = 0.1
       else
-        rspamd_logger.infox("cannot convert to spam probability: %s", reply.probability)
+        rspamd_logger.infox(task, "cannot convert to spam probability: %s", reply.probability)
       end
     end
 
index a3fdb0ec44b2c53ef8a84e8c46b0e3954dcbc8de..44eb40ad9b83231fd74426366e5ca9020e018ccd 100644 (file)
@@ -138,7 +138,7 @@ end
 local function history_save(task)
   local function redis_llen_cb(err, _)
     if err then
-      rspamd_logger.errx(task, 'got error %s when writing history row: %s',
+      rspamd_logger.errx(task, 'got error %s when writing history row',
           err)
     end
   end
@@ -188,7 +188,7 @@ local function handle_history_request(task, conn, from, to, reset)
   if reset then
     local function redis_ltrim_cb(err, _)
       if err then
-        rspamd_logger.errx(task, 'got error %s when resetting history: %s',
+        rspamd_logger.errx(task, 'got error %s when resetting history',
             err)
         conn:send_error(504, '{"error": "' .. err .. '"}')
       else
@@ -258,7 +258,7 @@ local function handle_history_request(task, conn, from, to, reset)
             (rspamd_util:get_ticks() - t1) * 1000.0)
         collectgarbage()
       else
-        rspamd_logger.errx(task, 'got error %s when getting history: %s',
+        rspamd_logger.errx(task, 'got error %s when getting history',
             err)
         conn:send_error(504, '{"error": "' .. err .. '"}')
       end
index a9a32e93f8dd8ece95e00c750f11ddd34051c9a1..0c82b167eacc481f8c04e8109a829c0a34db1e7c 100644 (file)
@@ -1282,7 +1282,7 @@ local function add_multimap_rule(key, newrule)
       if newrule.map_obj then
         ret = true
       else
-        rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %1',
+        rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %s',
             newrule['map'])
       end
     elseif newrule['type'] == 'received' then
@@ -1303,7 +1303,7 @@ local function add_multimap_rule(key, newrule)
         if newrule.map_obj then
           ret = true
         else
-          rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %1',
+          rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %s',
               newrule['map'])
         end
       else
@@ -1312,7 +1312,7 @@ local function add_multimap_rule(key, newrule)
         if newrule.map_obj then
           ret = true
         else
-          rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %1',
+          rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %s',
               newrule['map'])
         end
       end
@@ -1328,7 +1328,7 @@ local function add_multimap_rule(key, newrule)
       if newrule.map_obj then
         ret = true
       else
-        rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %1',
+        rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %s',
             newrule['map'])
       end
     elseif newrule['type'] == 'dnsbl' then
index 8700245a94e7bdf73dfd214c65f280ec7742fecf..d463658fa9d4bd2bb9335bdfcaf7881c3283761c 100644 (file)
@@ -373,7 +373,7 @@ local function ratelimit_cb(task)
   local function gen_check_cb(prefix, bucket, lim_name, lim_key)
     return function(err, data)
       if err then
-        rspamd_logger.errx('cannot check limit %s: %s %s', prefix, err, data)
+        rspamd_logger.errx('cannot check limit %s: %s', prefix, err)
       elseif type(data) == 'table' and data[1] then
         lua_util.debugm(N, task,
             "got reply for limit %s (%s / %s); %s burst, %s:%s dyn, %s leaked",
@@ -476,7 +476,7 @@ local function maybe_cleanup_pending(task)
         local bucket = v.bucket
         local function cleanup_cb(err, data)
           if err then
-            rspamd_logger.errx('cannot cleanup limit %s: %s %s', k, err, data)
+            rspamd_logger.errx('cannot cleanup limit %s: %s', k, err)
           else
             lua_util.debugm(N, task, 'cleaned pending bucked for %s: %s', k, data)
           end
index af4a4cd151a70799b58a7049bf8006d94feb4e05..b5b904b0053e28594c68381b31268c98d83de20f 100644 (file)
@@ -1077,7 +1077,7 @@ local function add_rbl(key, rbl, global_opts)
             rbl.selector_flatten)
 
         if not sel then
-          rspamd_logger.errx('invalid selector for rbl rule %s: %s', key, selector)
+          rspamd_logger.errx(rspamd_config, 'invalid selector for rbl rule %s: %s', key, selector)
           return false
         end
 
index 0f8e007237e5f87c385ec978d44e1f2f6712277b..c576e1325cbff273eb9d66585f16b09923fb5f92 100644 (file)
@@ -1275,7 +1275,7 @@ local function gen_redis_callback(handler, id)
                   ucl_err)
             else
               local obj = parser:get_object()
-              rspamd_logger.infox(task, "<%1> apply settings according to redis rule %2",
+              rspamd_logger.infox(task, "<%s> apply settings according to redis rule %s",
                   task:get_message_id(), id)
               apply_settings(task, obj, nil, 'redis')
               break
@@ -1283,7 +1283,7 @@ local function gen_redis_callback(handler, id)
           end
         end
       elseif err then
-        rspamd_logger.errx(task, 'Redis error: %1', err)
+        rspamd_logger.errx(task, 'Redis error: %s', err)
       end
     end
 
@@ -1371,7 +1371,7 @@ if set_section and set_section[1] and type(set_section[1]) == "string" then
     opaque_data = true
   }
   if not rspamd_config:add_map(map_attrs) then
-    rspamd_logger.errx(rspamd_config, 'cannot load settings from %1', set_section)
+    rspamd_logger.errx(rspamd_config, 'cannot load settings from %s', set_section)
   end
 elseif set_section and type(set_section) == "table" then
   settings_map_pool = rspamd_mempool.create()
index 3ea794495bee62b9ed29c3d79e39555e426c8fb6..8d8bd8367a0eab525f95ee96632a008641bd5bea 100644 (file)
@@ -221,7 +221,7 @@ local function handle_header_def(hline, cur_rule)
       })
       cur_rule['function'] = function(task)
         if not re then
-          rspamd_logger.errx(task, 're is missing for rule %1', h)
+          rspamd_logger.errx(task, 're is missing for rule %s', h)
           return 0
         end
 
@@ -272,7 +272,7 @@ local function handle_header_def(hline, cur_rule)
         elseif func == 'case' then
           cur_param['strong'] = true
         else
-          rspamd_logger.warnx(rspamd_config, 'Function %1 is not supported in %2',
+          rspamd_logger.warnx(rspamd_config, 'Function %s is not supported in %s',
               func, cur_rule['symbol'])
         end
       end, fun.tail(args))
@@ -314,7 +314,7 @@ end
 local function freemail_search(input)
   local res = 0
   local function trie_callback(number, pos)
-    lua_util.debugm(N, rspamd_config, 'Matched pattern %1 at pos %2', freemail_domains[number], pos)
+    lua_util.debugm(N, rspamd_config, 'Matched pattern %s at pos %s', freemail_domains[number], pos)
     res = res + 1
   end
 
@@ -369,7 +369,7 @@ local function gen_eval_rule(arg)
                 end
                 return 0
               else
-                rspamd_logger.infox(rspamd_config, 'cannot create regexp %1', re)
+                rspamd_logger.infox(rspamd_config, 'cannot create regexp %s', re)
                 return 0
               end
             end
@@ -461,7 +461,7 @@ local function gen_eval_rule(arg)
               end
             end
           else
-            rspamd_logger.infox(task, 'unimplemented mime check %1', arg)
+            rspamd_logger.infox(task, 'unimplemented mime check %s', arg)
           end
         end
 
@@ -576,7 +576,7 @@ local function maybe_parse_sa_function(line)
   local elts = split(line, '[^:]+')
   arg = elts[2]
 
-  lua_util.debugm(N, rspamd_config, 'trying to parse SA function %1 with args %2',
+  lua_util.debugm(N, rspamd_config, 'trying to parse SA function %s with args %s',
       elts[1], elts[2])
   local substitutions = {
     { '^exists:',
@@ -612,7 +612,7 @@ local function maybe_parse_sa_function(line)
         end
 
         if not func then
-          rspamd_logger.errx(task, 'cannot find appropriate eval rule for function %1',
+          rspamd_logger.errx(task, 'cannot find appropriate eval rule for function %s',
               arg)
         else
           return func(task)
@@ -685,7 +685,7 @@ local function process_sa_conf(f)
     end
     -- We have previous rule valid
     if not cur_rule['symbol'] then
-      rspamd_logger.errx(rspamd_config, 'bad rule definition: %1', cur_rule)
+      rspamd_logger.errx(rspamd_config, 'bad rule definition: %s', cur_rule)
     end
     rules[cur_rule['symbol']] = cur_rule
     cur_rule = {}
@@ -695,15 +695,15 @@ local function process_sa_conf(f)
   local function parse_score(words)
     if #words == 3 then
       -- score rule <x>
-      lua_util.debugm(N, rspamd_config, 'found score for %1: %2', words[2], words[3])
+      lua_util.debugm(N, rspamd_config, 'found score for %s: %s', words[2], words[3])
       return tonumber(words[3])
     elseif #words == 6 then
       -- score rule <x1> <x2> <x3> <x4>
       -- we assume here that bayes and network are enabled and select <x4>
-      lua_util.debugm(N, rspamd_config, 'found score for %1: %2', words[2], words[6])
+      lua_util.debugm(N, rspamd_config, 'found score for %s: %s', words[2], words[6])
       return tonumber(words[6])
     else
-      rspamd_logger.errx(rspamd_config, 'invalid score for %1', words[2])
+      rspamd_logger.errx(rspamd_config, 'invalid score for %s', words[2])
     end
 
     return 0
@@ -812,7 +812,7 @@ local function process_sa_conf(f)
           cur_rule['re'] = rspamd_regexp.create(cur_rule['re_expr'])
 
           if not cur_rule['re'] then
-            rspamd_logger.warnx(rspamd_config, "Cannot parse regexp '%1' for %2",
+            rspamd_logger.warnx(rspamd_config, "Cannot parse regexp '%s' for %s",
                 cur_rule['re_expr'], cur_rule['symbol'])
           else
             cur_rule['re']:set_max_hits(1)
@@ -829,8 +829,8 @@ local function process_sa_conf(f)
             cur_rule['mime'] = false
           end
 
-          if cur_rule['re'] and cur_rule['symbol'] and
-              (cur_rule['header'] or cur_rule['function']) then
+          if cur_rule['re'] and cur_rule['symbol']
+              and (cur_rule['header'] or cur_rule['function']) then
             valid_rule = true
             cur_rule['re']:set_max_hits(1)
             if cur_rule['header'] and cur_rule['ordinary'] then
@@ -894,7 +894,7 @@ local function process_sa_conf(f)
             cur_rule['function'] = func
             valid_rule = true
           else
-            rspamd_logger.infox(rspamd_config, 'unknown function %1', args)
+            rspamd_logger.infox(rspamd_config, 'unknown function %s', args)
           end
         end
       elseif words[1] == "body" then
@@ -931,7 +931,7 @@ local function process_sa_conf(f)
             cur_rule['function'] = func
             valid_rule = true
           else
-            rspamd_logger.infox(rspamd_config, 'unknown function %1', args)
+            rspamd_logger.infox(rspamd_config, 'unknown function %s', args)
           end
         end
       elseif words[1] == "rawbody" then
@@ -968,7 +968,7 @@ local function process_sa_conf(f)
             cur_rule['function'] = func
             valid_rule = true
           else
-            rspamd_logger.infox(rspamd_config, 'unknown function %1', args)
+            rspamd_logger.infox(rspamd_config, 'unknown function %s', args)
           end
         end
       elseif words[1] == "full" then
@@ -1006,7 +1006,7 @@ local function process_sa_conf(f)
             cur_rule['function'] = func
             valid_rule = true
           else
-            rspamd_logger.infox(rspamd_config, 'unknown function %1', args)
+            rspamd_logger.infox(rspamd_config, 'unknown function %s', args)
           end
         end
       elseif words[1] == "uri" then
@@ -1265,11 +1265,11 @@ local function post_process()
       if res then
         local nre = rspamd_regexp.create(nexpr)
         if not nre then
-          rspamd_logger.errx(rspamd_config, 'cannot apply replacement for rule %1', r)
+          rspamd_logger.errx(rspamd_config, 'cannot apply replacement for rule %s', r)
           --rule['re'] = nil
         else
           local old_max_hits = rule['re']:get_max_hits()
-          lua_util.debugm(N, rspamd_config, 'replace %1 -> %2', r, nexpr)
+          lua_util.debugm(N, rspamd_config, 'replace %s -> %s', r, nexpr)
           rspamd_config:replace_regexp({
             old_re = rule['re'],
             new_re = nre,
@@ -1306,8 +1306,7 @@ local function post_process()
         end
 
         if not r['re'] then
-          rspamd_logger.errx(task, 're is missing for rule %1 (%2 header)', k,
-              h['header'])
+          rspamd_logger.errx(task, 're is missing for rule %s', h)
           return 0
         end
 
@@ -1434,7 +1433,8 @@ local function post_process()
   fun.each(function(k, r)
     local f = function(task)
       if not r['re'] then
-        rspamd_logger.errx(task, 're is missing for rule %1', k)
+        rspamd_logger.errx(task, 're is missing for rule %s', k)
+        rspamd_logger.errx(task, 're is missing for rule %s', k)
         return 0
       end
 
@@ -1461,7 +1461,8 @@ local function post_process()
   fun.each(function(k, r)
     local f = function(task)
       if not r['re'] then
-        rspamd_logger.errx(task, 're is missing for rule %1', k)
+        rspamd_logger.errx(task, 're is missing for rule %s', k)
+        rspamd_logger.errx(task, 're is missing for rule %s', k)
         return 0
       end
 
@@ -1486,7 +1487,7 @@ local function post_process()
   fun.each(function(k, r)
     local f = function(task)
       if not r['re'] then
-        rspamd_logger.errx(task, 're is missing for rule %1', k)
+        rspamd_logger.errx(task, 're is missing for rule %s', k)
         return 0
       end
 
@@ -1629,8 +1630,8 @@ local function post_process()
             rspamd_config:register_dependency(k, rspamd_symbol)
             external_deps[k][rspamd_symbol] = true
             lua_util.debugm(N, rspamd_config,
-                'atom %1 is a direct foreign dependency, ' ..
-                    'register dependency for %2 on %3',
+                'atom %s is a direct foreign dependency, ' ..
+                    'register dependency for %s on %s',
                 a, k, rspamd_symbol)
           end
         end
@@ -1659,8 +1660,8 @@ local function post_process()
                 rspamd_config:register_dependency(k, dep)
                 external_deps[k][dep] = true
                 lua_util.debugm(N, rspamd_config,
-                    'atom %1 is an indirect foreign dependency, ' ..
-                        'register dependency for %2 on %3',
+                    'atom %s is an indirect foreign dependency, ' ..
+                        'register dependency for %s on %s',
                     a, k, dep)
                 nchanges = nchanges + 1
               end
@@ -1694,10 +1695,10 @@ local function post_process()
   -- Logging output
   if freemail_domains then
     freemail_trie = rspamd_trie.create(freemail_domains)
-    rspamd_logger.infox(rspamd_config, 'loaded %1 freemail domains definitions',
+    rspamd_logger.infox(rspamd_config, 'loaded %s freemail domains definitions',
         #freemail_domains)
   end
-  rspamd_logger.infox(rspamd_config, 'loaded %1 blacklist/whitelist elements',
+  rspamd_logger.infox(rspamd_config, 'loaded %s blacklist/whitelist elements',
       sa_lists['elts'])
 end
 
@@ -1739,7 +1740,7 @@ if type(section) == "table" then
                 process_sa_conf(f)
                 has_rules = true
               else
-                rspamd_logger.errx(rspamd_config, "cannot open %1", matched)
+                rspamd_logger.errx(rspamd_config, "cannot open %s", matched)
               end
             end
           end
@@ -1758,7 +1759,7 @@ if type(section) == "table" then
               process_sa_conf(f)
               has_rules = true
             else
-              rspamd_logger.errx(rspamd_config, "cannot open %1", matched)
+              rspamd_logger.errx(rspamd_config, "cannot open %s", matched)
             end
           end
         end
index 7ba45528986d8d3f139973ca4f41aea86c0802f1..7c7214b55eac541b09de766e88aeb9e21603b19c 100644 (file)
@@ -107,10 +107,10 @@ local function process_trie_file(symbol, cf)
   local file = io.open(cf['file'])
 
   if not file then
-    rspamd_logger.errx(rspamd_config, 'Cannot open trie file %1', cf['file'])
+    rspamd_logger.errx(rspamd_config, 'Cannot open trie file %s', cf['file'])
   else
     if cf['binary'] then
-      rspamd_logger.errx(rspamd_config, 'binary trie patterns are not implemented yet: %1',
+      rspamd_logger.errx(rspamd_config, 'binary trie patterns are not implemented yet: %s',
           cf['file'])
     else
       for line in file:lines() do
@@ -123,7 +123,7 @@ end
 
 local function process_trie_conf(symbol, cf)
   if type(cf) ~= 'table' then
-    rspamd_logger.errx(rspamd_config, 'invalid value for symbol %1: "%2", expected table',
+    rspamd_logger.errx(rspamd_config, 'invalid value for symbol %s: "%s", expected table',
         symbol, cf)
     return
   end
@@ -145,17 +145,17 @@ if opts then
 
   if #raw_patterns > 0 then
     raw_trie = rspamd_trie.create(raw_patterns)
-    rspamd_logger.infox(rspamd_config, 'registered raw search trie from %1 patterns', #raw_patterns)
+    rspamd_logger.infox(rspamd_config, 'registered raw search trie from %s patterns', #raw_patterns)
   end
 
   if #mime_patterns > 0 then
     mime_trie = rspamd_trie.create(mime_patterns)
-    rspamd_logger.infox(rspamd_config, 'registered mime search trie from %1 patterns', #mime_patterns)
+    rspamd_logger.infox(rspamd_config, 'registered mime search trie from %s patterns', #mime_patterns)
   end
 
   if #body_patterns > 0 then
     body_trie = rspamd_trie.create(body_patterns)
-    rspamd_logger.infox(rspamd_config, 'registered body search trie from %1 patterns', #body_patterns)
+    rspamd_logger.infox(rspamd_config, 'registered body search trie from %s patterns', #body_patterns)
   end
 
   local id = -1