aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-01-20 13:29:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-01-20 13:29:22 +0000
commitb9f51206b4568a2cf4243bfdc5d192c1804d0b8e (patch)
tree3ff63f17ed6fa46fb751c5d5f597c92f6d9fb031 /src/libutil
parent303d3e7797a58524d0bbba9269314e54efe8a14c (diff)
downloadrspamd-b9f51206b4568a2cf4243bfdc5d192c1804d0b8e.tar.gz
rspamd-b9f51206b4568a2cf4243bfdc5d192c1804d0b8e.zip
[Project] Enable fast debug lookup for some modules
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/logger.c9
-rw-r--r--src/libutil/logger.h37
-rw-r--r--src/libutil/map.c6
-rw-r--r--src/libutil/map_private.h6
-rw-r--r--src/libutil/radix.c6
5 files changed, 40 insertions, 24 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index d69c0f038..487ca2633 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -115,6 +115,12 @@ static void file_log_function (const gchar *module,
gint log_level, const gchar *message,
gpointer arg);
+guint rspamd_task_log_id = (guint)-1;
+RSPAMD_CONSTRUCTOR(rspamd_task_log_init)
+{
+ rspamd_task_log_id = rspamd_logger_add_debug_module("task");
+}
+
/**
* Calculate checksum for log line (used for repeating logic)
*/
@@ -1358,6 +1364,7 @@ rspamd_logger_add_debug_module (const gchar *mname)
m->mname = g_strdup (mname);
m->id = rspamd_logger_allocate_mod_bit ();
clrbit (log_modules->bitset, m->id);
+ g_hash_table_insert (log_modules->modules, m->mname, m);
}
return m->id;
@@ -1383,7 +1390,7 @@ rspamd_logger_configure_modules (GHashTable *mods_enabled)
while (g_hash_table_iter_next (&it, &k, &v)) {
id = rspamd_logger_add_debug_module ((const gchar *)k);
-
+ msg_info ("enable debugging for module %s (%d)", (const gchar *)k, id);
setbit (log_modules->bitset, id);
}
} \ No newline at end of file
diff --git a/src/libutil/logger.h b/src/libutil/logger.h
index 3f3f28ef6..9b94c03ee 100644
--- a/src/libutil/logger.h
+++ b/src/libutil/logger.h
@@ -106,9 +106,9 @@ guint rspamd_logger_add_debug_module (const gchar *mod);
* Macro to use for faster debug modules
*/
#define INIT_LOG_MODULE(mname) \
- static guint mname##_log_id = (guint)-1; \
- static RSPAMD_CONSTRUCTOR(mname##_log_init) { \
- mname##_log_id = rspamd_logger_add_debug_module(#mname); \
+ static guint rspamd_##mname##_log_id = (guint)-1; \
+ RSPAMD_CONSTRUCTOR(rspamd_##mname##_log_init) { \
+ rspamd_##mname##_log_id = rspamd_logger_add_debug_module(#mname); \
}
void rspamd_logger_configure_modules (GHashTable *mods_enabled);
@@ -185,6 +185,8 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
/* Typical functions */
+extern guint rspamd_task_log_id;
+
/* Logging in postfix style */
#define msg_err(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
NULL, NULL, \
@@ -202,9 +204,10 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
NULL, NULL, \
G_STRFUNC, \
__VA_ARGS__)
-#define debug_task(...) rspamd_conditional_debug (NULL, \
+
+#define debug_task(...) rspamd_conditional_debug_fast (NULL, \
task->from_addr, \
- "task", task->task_pool->tag.uid, \
+ rspamd_task_log_id, "task", task->task_pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
@@ -221,8 +224,8 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
task->task_pool->tag.tagname, task->task_pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_task(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
- "task", task->task_pool->tag.uid, \
+#define msg_debug_task(...) rspamd_conditional_debug_fast (NULL, task->from_addr, \
+ rspamd_task_log_id, "task", task->task_pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
#define msg_err_task_encrypted(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL|RSPAMD_LOG_ENCRYPTED, \
@@ -237,10 +240,6 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
task->task_pool->tag.tagname, task->task_pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_task_encrypted(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG|RSPAMD_LOG_ENCRYPTED, \
- task->task_pool->tag.tagname, task->task_pool->tag.uid, \
- G_STRFUNC, \
- __VA_ARGS__)
/* Check for NULL pointer first */
#define msg_err_task_check(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
task ? task->task_pool->tag.tagname : NULL, task ? task->task_pool->tag.uid : NULL, \
@@ -254,8 +253,9 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
task ? task->task_pool->tag.tagname : NULL, task ? task->task_pool->tag.uid : NULL, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_task_check(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
- task ? task->task_pool->tag.tagname : NULL, task ? task->task_pool->tag.uid : NULL, \
+#define msg_debug_task_check(...) rspamd_conditional_debug_fast (NULL, \
+ task ? task->from_addr : NULL, \
+ rspamd_task_log_id, "task", task ? task->task_pool->tag.uid : NULL, \
G_STRFUNC, \
__VA_ARGS__)
@@ -272,7 +272,7 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
pool->tag.tagname, pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_pool(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+#define msg_debug_pool(...) rspamd_conditional_debug (NULL, NULL, \
pool->tag.tagname, pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
@@ -285,12 +285,13 @@ ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_info_pool_check(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \
+#define msg_info_pool_check(...) rspamd_conditional_debug (NULL, NULL, \
+ G_LOG_LEVEL_INFO, \
pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_pool_check(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+#define msg_debug_pool_check(...) rspamd_conditional_debug (NULL, NULL, \
pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \
- G_STRFUNC, \
- __VA_ARGS__)
+ G_STRFUNC, \
+ __VA_ARGS__)
#endif
diff --git a/src/libutil/map.c b/src/libutil/map.c
index 01bafc82c..aeb7f9ed3 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -66,6 +66,12 @@ struct rspamd_http_map_cached_cbdata {
time_t last_checked;
};
+guint rspamd_map_log_id = (guint)-1;
+RSPAMD_CONSTRUCTOR(rspamd_map_log_init)
+{
+ rspamd_map_log_id = rspamd_logger_add_debug_module("map");
+}
+
/**
* Write HTTP request
*/
diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h
index fd2098cd1..1de6fb942 100644
--- a/src/libutil/map_private.h
+++ b/src/libutil/map_private.h
@@ -24,7 +24,7 @@
#include "ref.h"
typedef void (*rspamd_map_dtor) (gpointer p);
-
+extern guint rspamd_map_log_id;
#define msg_err_map(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
"map", map->tag, \
G_STRFUNC, \
@@ -37,8 +37,8 @@ typedef void (*rspamd_map_dtor) (gpointer p);
"map", map->tag, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_map(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
- "map", map->tag, \
+#define msg_debug_map(...) rspamd_conditional_debug_fast (NULL, NULL, \
+ rspamd_map_log_id, "map", map->tag, \
G_STRFUNC, \
__VA_ARGS__)
diff --git a/src/libutil/radix.c b/src/libutil/radix.c
index bb295d7d1..8c2258459 100644
--- a/src/libutil/radix.c
+++ b/src/libutil/radix.c
@@ -31,11 +31,13 @@
"radix", tree->pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
-#define msg_debug_radix(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
- "radix", tree->pool->tag.uid, \
+#define msg_debug_radix(...) rspamd_conditional_debug_fast (NULL, NULL, \
+ rspamd_radix_log_id, "radix", tree->pool->tag.uid, \
G_STRFUNC, \
__VA_ARGS__)
+INIT_LOG_MODULE(radix)
+
struct radix_tree_compressed {
rspamd_mempool_t *pool;
size_t size;