]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Improve some logging stuff 5281/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 7 Jan 2025 13:46:12 +0000 (13:46 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 7 Jan 2025 13:46:12 +0000 (13:46 +0000)
lualib/lua_redis.lua
src/libserver/logger/logger.c

index 48ea1b6ede00fed1db8b918e6c59641a3d4c29f3..85f5ebc7a1a2332eb348d2c44abc1d82b06d79c3 100644 (file)
@@ -1738,11 +1738,10 @@ exports.request = function(redis_params, attrs, req)
     opts.dbname = redis_params.db
   end
 
-  lutil.debugm(N, 'perform generic request to redis server' ..
-      ' (host=%s, timeout=%s): cmd: %s, arguments: %s', addr,
-      opts.timeout, opts.cmd, opts.args)
-
   if opts.callback then
+    lutil.debugm(N, 'perform generic async request to redis server' ..
+        ' (host=%s, timeout=%s): cmd: %s, arguments: %s', addr,
+        opts.timeout, opts.cmd, opts.args)
     local ret, conn = rspamd_redis.make_request(opts)
     if not ret then
       logger.errx(log_obj, 'cannot execute redis request')
@@ -1752,6 +1751,9 @@ exports.request = function(redis_params, attrs, req)
     return ret, conn, addr
   else
     -- Coroutines version
+    lutil.debugm(N, 'perform generic coroutine request to redis server' ..
+        ' (host=%s, timeout=%s): cmd: %s, arguments: %s', addr,
+        opts.timeout, opts.cmd, opts.args)
     local ret, conn = rspamd_redis.connect_sync(opts)
     if not ret then
       logger.errx(log_obj, 'cannot execute redis request')
index 25818e7a5526b391bd28666486fe0536002ab59c..dc0a85a05ae196d7ef486f81ef07120c102a0505 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -1026,6 +1026,18 @@ log_time(double now, rspamd_logger_t *rspamd_log, char *timebuf,
        }
 }
 
+static inline int
+rspamd_log_id_strlen(const char *id)
+{
+       for (int i = 0; i < RSPAMD_LOG_ID_LEN; i++) {
+               if (G_UNLIKELY(id[i] == '\0')) {
+                       return i;
+               }
+       }
+
+       return RSPAMD_LOG_ID_LEN;
+}
+
 void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx,
                                                 double ts,
                                                 const char *module,
@@ -1235,9 +1247,7 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx,
                m = modulebuf;
 
                if (id != NULL) {
-                       unsigned int slen = strlen(id);
-                       slen = MIN(RSPAMD_LOG_ID_LEN, slen);
-                       mr = rspamd_snprintf(m, mremain, "<%*.s>; ", slen,
+                       mr = rspamd_snprintf(m, mremain, "<%*.s>; ", rspamd_log_id_strlen(id),
                                                                 id);
                        m += mr;
                        mremain -= mr;
@@ -1289,6 +1299,14 @@ void rspamd_log_fill_iov(struct rspamd_logger_iov_ctx *iov_ctx,
                if (logger->log_level == G_LOG_LEVEL_DEBUG) {
                        iov_ctx->iov[niov].iov_base = (void *) timebuf;
                        iov_ctx->iov[niov++].iov_len = strlen(timebuf);
+                       if (id != NULL) {
+                               iov_ctx->iov[niov].iov_base = (void *) "; ";
+                               iov_ctx->iov[niov++].iov_len = 2;
+                               iov_ctx->iov[niov].iov_base = (void *) id;
+                               iov_ctx->iov[niov++].iov_len = rspamd_log_id_strlen(id);
+                               iov_ctx->iov[niov].iov_base = (void *) ";";
+                               iov_ctx->iov[niov++].iov_len = 1;
+                       }
                        iov_ctx->iov[niov].iov_base = (void *) " ";
                        iov_ctx->iov[niov++].iov_len = 1;
                }