From ffc1272554c52d9020076c7b184c723aaee7e07d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 23 Oct 2022 22:16:54 +0100 Subject: [PATCH] [Minor] Improve logging --- src/libserver/hyperscan_tools.cxx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx index bb1c9ffbc..ff566b9be 100644 --- a/src/libserver/hyperscan_tools.cxx +++ b/src/libserver/hyperscan_tools.cxx @@ -37,14 +37,22 @@ "hyperscan", "", \ RSPAMD_LOG_FUNC, \ __VA_ARGS__) +#define msg_info_hyperscan_lambda(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \ + "hyperscan", "", \ + log_func, \ + __VA_ARGS__) #define msg_err_hyperscan(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ "hyperscan", "", \ RSPAMD_LOG_FUNC, \ __VA_ARGS__) -#define msg_debug_hyperscan(...) rspamd_conditional_debug_fast (NULL, NULL, \ +#define msg_debug_hyperscan(...) rspamd_conditional_debug_fast (nullptr, nullptr, \ rspamd_hyperscan_log_id, "hyperscan", "", \ RSPAMD_LOG_FUNC, \ __VA_ARGS__) +#define msg_debug_hyperscan_lambda(...) rspamd_conditional_debug_fast (nullptr, nullptr, \ + rspamd_hyperscan_log_id, "hyperscan", "", \ + log_func, \ + __VA_ARGS__) INIT_LOG_MODULE_PUBLIC(hyperscan) @@ -163,6 +171,7 @@ public: auto cleanup_maybe() -> void { /* We clean dir merely if we are running from the main process */ if (rspamd_current_worker == nullptr) { + const auto *log_func = RSPAMD_LOG_FUNC; auto cleanup_dir = [&](std::string_view dir) -> void { for (const auto &ext : cache_extensions) { glob_t globbuf; @@ -177,18 +186,18 @@ public: struct stat st; if (stat(path, &st) == -1) { - msg_debug_hyperscan("cannot stat file %s: %s", + msg_debug_hyperscan_lambda("cannot stat file %s: %s", path, strerror(errno)); continue; } if (S_ISREG(st.st_mode)) { if (!known_cached_files.contains(path)) { - msg_info_hyperscan("remove stale hyperscan file %s", path); + msg_info_hyperscan_lambda("remove stale hyperscan file %s", path); unlink(path); } else { - msg_debug_hyperscan("found known hyperscan file %s, size: %Hz", + msg_debug_hyperscan_lambda("found known hyperscan file %s, size: %Hz", path, st.st_size); } } @@ -262,6 +271,7 @@ hs_shared_from_serialized(raii_mmaped_file &&map) -> tl::expected tl::expected { auto &hs_cache = hs_known_files_cache::get(); + const auto *log_func = RSPAMD_LOG_FUNC; return raii_mmaped_file::mmap_shared(fname, O_RDONLY, PROT_READ) .and_then([&](T &&cached_serialized) -> tl::expected { @@ -285,11 +295,11 @@ auto load_cached_hs_file(const char *fname) -> tl::expected tl::expected %s: %s", + msg_info_hyperscan_lambda("cannot rename %s -> %s: %s", tmpfile_name.c_str(), unserialized_fname.c_str(), strerror(errno)); -- 2.39.5