From a7e9c6c403bde957b8f07895bb2f7f2b13135fb0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 24 Jan 2016 23:31:45 +0000 Subject: [PATCH] Add logging macroes with guards --- src/libutil/addr.c | 10 +++++----- src/libutil/logger.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/libutil/addr.c b/src/libutil/addr.c index f5d1415d9..85568f7c8 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -896,7 +896,7 @@ rspamd_check_port_priority (const char *line, guint default_port, real_priority = strtoul (err_str + 1, &err_str_prio, 10); if (err_str_prio && *err_str_prio != '\0') { - msg_err_pool ( + msg_err_pool_check ( "cannot parse priority: %s, at symbol %c, error: %s", line, *err_str_prio, @@ -906,7 +906,7 @@ rspamd_check_port_priority (const char *line, guint default_port, } } else if (err_str && *err_str != '\0') { - msg_err_pool ( + msg_err_pool_check ( "cannot parse port: %s, at symbol %c, error: %s", line, *err_str, @@ -982,7 +982,7 @@ rspamd_resolve_addrs (const char *begin, size_t len, GPtrArray **addrs, freeaddrinfo (res); } else { - msg_err_pool ("address resolution for %s failed: %s", + msg_err_pool_check ("address resolution for %s failed: %s", addr_cpy, gai_strerror (r)); g_free (addr_cpy); @@ -1028,7 +1028,7 @@ rspamd_parse_host_port_priority (const gchar *str, p = strchr (str, ']'); if (p == NULL) { - msg_err ("cannot parse address definition %s: %s", + msg_err_pool_check ("cannot parse address definition %s: %s", str, strerror (EINVAL)); @@ -1058,7 +1058,7 @@ rspamd_parse_host_port_priority (const gchar *str, } if (!rspamd_parse_inet_address (&cur_addr, str, 0)) { - msg_err_pool ("cannot parse unix socket definition %s: %s", + msg_err_pool_check ("cannot parse unix socket definition %s: %s", str, strerror (errno)); diff --git a/src/libutil/logger.h b/src/libutil/logger.h index 42307fc6c..7bf8307c8 100644 --- a/src/libutil/logger.h +++ b/src/libutil/logger.h @@ -174,6 +174,23 @@ const guint64* rspamd_log_counters (rspamd_logger_t *logger); 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, \ + G_STRFUNC, \ + __VA_ARGS__) +#define msg_warn_task_check(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \ + task ? task->task_pool->tag.tagname : NULL, task ? task->task_pool->tag.uid : NULL, \ + G_STRFUNC, \ + __VA_ARGS__) +#define msg_info_task_check(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \ + 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, \ + G_STRFUNC, \ + __VA_ARGS__) /* Use the following macros if you have `pool` in the function */ #define msg_err_pool(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ @@ -192,4 +209,21 @@ const guint64* rspamd_log_counters (rspamd_logger_t *logger); pool->tag.tagname, pool->tag.uid, \ G_STRFUNC, \ __VA_ARGS__) +/* Check for NULL pointer first */ +#define msg_err_pool_check(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ + pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \ + G_STRFUNC, \ + __VA_ARGS__) +#define msg_warn_pool_check(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \ + 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, \ + 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, \ + pool ? pool->tag.tagname : NULL, pool ? pool->tag.uid : NULL, \ + G_STRFUNC, \ + __VA_ARGS__) #endif -- 2.39.5