commit 25e7d7f: [Minor] Slightly improve logging

Vsevolod Stakhov vsevolod at rspamd.com
Mon Jul 29 17:49:37 UTC 2024


Author: Vsevolod Stakhov
Date: 2023-12-04 15:01:09 +0000
URL: https://github.com/rspamd/rspamd/commit/25e7d7ff17056d427e46a92d50a97355981c0e7f

[Minor] Slightly improve logging

---
 lualib/lua_redis.lua | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua
index 3163b45c6..edaae9443 100644
--- a/lualib/lua_redis.lua
+++ b/lualib/lua_redis.lua
@@ -1207,9 +1207,9 @@ local function load_script_task(script, task, is_write)
       else
         opt.upstream:ok()
         logger.infox(task,
-            "uploaded redis script to %s with id %s, sha: %s",
+            "uploaded redis script to %s %s %s, sha: %s",
             opt.upstream:get_addr():to_string(true),
-            script.id, data)
+            script.filename and "from file" or "with id", script.filename or script.id, data)
         script.sha = data -- We assume that sha is the same on all servers
       end
       script.in_flight = script.in_flight - 1
@@ -1244,16 +1244,18 @@ local function load_script_taskless(script, cfg, ev_base, is_write)
     opt.is_write = is_write
     opt.callback = function(err, data)
       if err then
-        logger.errx(cfg, 'cannot upload script to %s: %s; registered from: %s:%s',
+        logger.errx(cfg, 'cannot upload script to %s: %s; registered from: %s:%s, filename: %s',
             opt.upstream:get_addr():to_string(true),
-            err, script.caller.short_src, script.caller.currentline)
+            err, script.caller.short_src, script.caller.currentline, script.filename)
         opt.upstream:fail()
         script.fatal_error = err
       else
         opt.upstream:ok()
         logger.infox(cfg,
-            "uploaded redis script to %s with id %s, sha: %s",
-            opt.upstream:get_addr():to_string(true), script.id, data)
+            "uploaded redis script to %s %s %s, sha: %s",
+            opt.upstream:get_addr():to_string(true),
+            script.filename and "from file" or "with id", script.filename or script.id,
+            data)
         script.sha = data -- We assume that sha is the same on all servers
         script.fatal_error = nil
       end
@@ -1284,7 +1286,7 @@ local function load_redis_script(script, cfg, ev_base, _)
   end
 end
 
-local function add_redis_script(script, redis_params, caller_level)
+local function add_redis_script(script, redis_params, caller_level, maybe_filename)
   if not caller_level then
     caller_level = 2
   end
@@ -1296,7 +1298,8 @@ local function add_redis_script(script, redis_params, caller_level)
     redis_params = redis_params,
     script = script,
     waitq = {}, -- callbacks pending for script being loaded
-    id = #redis_scripts + 1
+    id = #redis_scripts + 1,
+    filename = maybe_filename,
   }
 
   -- Register on load function
@@ -1333,25 +1336,26 @@ local function load_redis_script_from_file(filename, redis_params, dir)
   if not dir then
     dir = rspamd_paths.LUALIBDIR
   end
+  local path = filename
   if filename:sub(1, 1) ~= package.config:sub(1, 1) then
     -- Relative path
-    filename = lua_util.join_path(dir, "redis_scripts", filename)
+    path = lua_util.join_path(dir, "redis_scripts", filename)
   end
   -- Read file contents
-  local file = io.open(filename, "r")
+  local file = io.open(path, "r")
   if not file then
-    rspamd_logger.errx("failed to open Redis script file: %s", filename)
+    rspamd_logger.errx("failed to open Redis script file: %s", path)
     return nil
   end
   local script = file:read("*all")
   if not script then
-    rspamd_logger.errx("failed to load Redis script file: %s", filename)
+    rspamd_logger.errx("failed to load Redis script file: %s", path)
     return nil
   end
   file:close()
   script = lua_util.strip_lua_comments(script)
 
-  return add_redis_script(script, redis_params, 3)
+  return add_redis_script(script, redis_params, 3, filename)
 end
 
 exports.load_redis_script_from_file = load_redis_script_from_file


More information about the Commits mailing list