]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Improve logging
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sun, 13 Jul 2025 14:56:58 +0000 (15:56 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sun, 13 Jul 2025 14:56:58 +0000 (15:56 +0100)
src/libserver/re_cache.c
src/lua/lua_config.c

index 7c5e146162f5d6f49e70f52fe97a051966c3a861..06ba26528df032462aaa0fc6a9a63b5a14a93623 100644 (file)
@@ -2215,21 +2215,27 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents)
                if (re_class->type_len > 0) {
                        if (!cbdata->silent) {
                                msg_info_re_cache(
-                                       "skip already valid class %s(%*s) to cache %6s, %d regexps",
+                                       "skip already valid class %s(%*s) to cache %6s, %d regexps%s%s%s",
                                        rspamd_re_cache_type_to_string(re_class->type),
                                        (int) re_class->type_len - 1,
                                        re_class->type_data,
                                        re_class->hash,
-                                       n);
+                                       n,
+                                       cache->scope ? " for scope '" : "",
+                                       cache->scope ? cache->scope : "",
+                                       cache->scope ? "'" : "");
                        }
                }
                else {
                        if (!cbdata->silent) {
                                msg_info_re_cache(
-                                       "skip already valid class %s to cache %6s, %d regexps",
+                                       "skip already valid class %s to cache %6s, %d regexps%s%s%s",
                                        rspamd_re_cache_type_to_string(re_class->type),
                                        re_class->hash,
-                                       n);
+                                       n,
+                                       cache->scope ? " for scope '" : "",
+                                       cache->scope ? cache->scope : "",
+                                       cache->scope ? "'" : "");
                        }
                }
 
@@ -2438,21 +2444,27 @@ rspamd_re_cache_compile_timer_cb(EV_P_ ev_timer *w, int revents)
 
                if (re_class->type_len > 0) {
                        msg_info_re_cache(
-                               "compiled class %s(%*s) to cache %6s, %d/%d regexps",
+                               "compiled class %s(%*s) to cache %6s, %d/%d regexps%s%s%s",
                                rspamd_re_cache_type_to_string(re_class->type),
                                (int) re_class->type_len - 1,
                                re_class->type_data,
                                re_class->hash,
                                n,
-                               (int) g_hash_table_size(re_class->re));
+                               (int) g_hash_table_size(re_class->re),
+                               cache->scope ? " for scope '" : "",
+                               cache->scope ? cache->scope : "",
+                               cache->scope ? "'" : "");
                }
                else {
                        msg_info_re_cache(
-                               "compiled class %s to cache %6s, %d/%d regexps",
+                               "compiled class %s to cache %6s, %d/%d regexps%s%s%s",
                                rspamd_re_cache_type_to_string(re_class->type),
                                re_class->hash,
                                n,
-                               (int) g_hash_table_size(re_class->re));
+                               (int) g_hash_table_size(re_class->re),
+                               cache->scope ? " for scope '" : "",
+                               cache->scope ? cache->scope : "",
+                               cache->scope ? "'" : "");
                }
 
                cbdata->total += n;
@@ -3059,16 +3071,27 @@ rspamd_re_cache_load_hyperscan(struct rspamd_re_cache *cache,
 
        if (has_valid) {
                if (all_valid) {
-                       msg_info_re_cache("full hyperscan database of %d regexps has been loaded", total);
+                       msg_info_re_cache("full hyperscan database of %d regexps has been loaded%s%s%s",
+                                                         total,
+                                                         cache->scope ? " for scope '" : "",
+                                                         cache->scope ? cache->scope : "",
+                                                         cache->scope ? "'" : "");
                        cache->hyperscan_loaded = RSPAMD_HYPERSCAN_LOADED_FULL;
                }
                else {
-                       msg_info_re_cache("partial hyperscan database of %d regexps has been loaded", total);
+                       msg_info_re_cache("partial hyperscan database of %d regexps has been loaded%s%s%s",
+                                                         total,
+                                                         cache->scope ? " for scope '" : "",
+                                                         cache->scope ? cache->scope : "",
+                                                         cache->scope ? "'" : "");
                        cache->hyperscan_loaded = RSPAMD_HYPERSCAN_LOADED_PARTIAL;
                }
        }
        else {
-               msg_info_re_cache("hyperscan database has NOT been loaded; no valid expressions");
+               msg_info_re_cache("hyperscan database has NOT been loaded; no valid expressions%s%s%s",
+                                                 cache->scope ? " for scope '" : "",
+                                                 cache->scope ? cache->scope : "",
+                                                 cache->scope ? "'" : "");
                cache->hyperscan_loaded = RSPAMD_HYPERSCAN_LOAD_ERROR;
        }
 
index 5416eae3cf86aea42e1da4aa0da6c233de0ab8fc..c9bd40691ca964cda4a90c27083e81de26f6c67d 100644 (file)
@@ -5397,6 +5397,13 @@ lua_config_set_regexp_scope_loaded(lua_State *L)
 
                if (loaded) {
                        rspamd_re_cache_set_flags(cfg->re_cache, scope, RSPAMD_RE_CACHE_FLAG_LOADED);
+
+                       /* When marking a scope as loaded, we also need to initialize it
+                        * to compute the hash for each re_class */
+                       struct rspamd_re_cache *target_cache = rspamd_re_cache_find_scope(cfg->re_cache, scope);
+                       if (target_cache) {
+                               rspamd_re_cache_init(target_cache, cfg);
+                       }
                }
                else {
                        rspamd_re_cache_clear_flags(cfg->re_cache, scope, RSPAMD_RE_CACHE_FLAG_LOADED);