]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
More logger fixes.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Aug 2015 15:41:05 +0000 (16:41 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 28 Aug 2015 15:41:05 +0000 (16:41 +0100)
src/libserver/events.c
src/libserver/html.c
src/libserver/protocol.c

index 9bf86eb96869f4fa66bf83cd292976acb9134074..a50c122f3d7ee341adc85bb488f4d3be8d1e0752 100644 (file)
 #define RSPAMD_SESSION_IS_WATCHING(s) ((s)->flags & RSPAMD_SESSION_FLAG_WATCHING)
 #define RSPAMD_SESSION_IS_DESTROYING(s) ((s)->flags & RSPAMD_SESSION_FLAG_DESTROYING)
 
+#define msg_err_session(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
+        session->pool->tag.tagname, session->pool->tag.uid, \
+        G_STRFUNC, \
+        __VA_ARGS__)
+#define msg_warn_session(...)   rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
+        session->pool->tag.tagname, session->pool->tag.uid, \
+        G_STRFUNC, \
+        __VA_ARGS__)
+#define msg_info_session(...)   rspamd_default_log_function (G_LOG_LEVEL_INFO, \
+        session->pool->tag.tagname, session->pool->tag.uid, \
+        G_STRFUNC, \
+        __VA_ARGS__)
+#define msg_debug_session(...)  rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+        session->pool->tag.tagname, session->pool->tag.uid, \
+        G_STRFUNC, \
+        __VA_ARGS__)
+
 struct rspamd_async_watcher {
        event_watcher_t cb;
        guint remain;
@@ -119,7 +136,7 @@ rspamd_session_add_event (struct rspamd_async_session *session,
        struct rspamd_async_event *new;
 
        if (session == NULL) {
-               msg_info ("session is NULL");
+               msg_info_session ("session is NULL");
                return;
        }
 
@@ -139,7 +156,7 @@ rspamd_session_add_event (struct rspamd_async_session *session,
 
        g_hash_table_insert (session->events, new, new);
 
-       msg_debug ("added event: %p, pending %d events, subsystem: %s",
+       msg_debug_session ("added event: %p, pending %d events, subsystem: %s",
                user_data,
                g_hash_table_size (session->events),
                g_quark_to_string (subsystem));
@@ -153,7 +170,7 @@ rspamd_session_remove_event (struct rspamd_async_session *session,
        struct rspamd_async_event search_ev, *found_ev;
 
        if (session == NULL) {
-               msg_info ("session is NULL");
+               msg_info_session ("session is NULL");
                return;
        }
 
@@ -163,7 +180,7 @@ rspamd_session_remove_event (struct rspamd_async_session *session,
        found_ev = g_hash_table_lookup (session->events, &search_ev);
        g_assert (found_ev != NULL);
 
-       msg_debug ("removed event: %p, subsystem: %s, pending %d events", ud,
+       msg_debug_session ("removed event: %p, subsystem: %s, pending %d events", ud,
                        g_quark_to_string (found_ev->subsystem),
                        g_hash_table_size (session->events));
        /* Remove event */
@@ -205,7 +222,7 @@ gboolean
 rspamd_session_destroy (struct rspamd_async_session *session)
 {
        if (session == NULL) {
-               msg_info ("session is NULL");
+               msg_info_session ("session is NULL");
                return FALSE;
        }
 
index 4674ee371a30213f5470c3906308da312061751e..401c13f7a82cb5837067fccc1c987a102f29e91b 100644 (file)
@@ -865,7 +865,7 @@ rspamd_html_url_is_phished (rspamd_mempool_t *pool,
                        *url_found = TRUE;
                }
                else {
-                       msg_info ("extract of url '%s' failed: %s",
+                       msg_info_pool ("extract of url '%s' failed: %s",
                                        url_str,
                                        rspamd_url_strerror (rc));
                }
@@ -901,7 +901,7 @@ rspamd_html_process_tag (rspamd_mempool_t *pool, struct html_content *hc,
 
                if (tag->flags & FL_CLOSING) {
                        if (!*cur_level) {
-                               msg_debug ("bad parent node");
+                               msg_debug_pool ("bad parent node");
                                g_node_destroy (nnode);
                                return FALSE;
                        }
@@ -909,7 +909,7 @@ rspamd_html_process_tag (rspamd_mempool_t *pool, struct html_content *hc,
                        g_node_append (*cur_level, nnode);
 
                        if (!rspamd_html_check_balance (nnode, cur_level)) {
-                               msg_debug (
+                               msg_debug_pool (
                                                "mark part as unbalanced as it has not pairable closing tags");
                                hc->flags |= RSPAMD_HTML_FLAG_UNBALANCED;
                                *balanced = FALSE;
@@ -1482,13 +1482,13 @@ rspamd_html_process_style (rspamd_mempool_t *pool, struct html_block *bl,
                                        || (klen == 10 && g_ascii_strncasecmp (key, "font-color", 10) == 0)) {
 
                                                rspamd_html_process_color (c, p - c, &bl->font_color);
-                                               msg_debug ("got color: %xd", bl->font_color.d.val);
+                                               msg_debug_pool ("got color: %xd", bl->font_color.d.val);
                                        }
                                        if (klen == 16 && g_ascii_strncasecmp (key,
                                                        "background-color", 16) == 0) {
 
                                                rspamd_html_process_color (c, p - c, &bl->background_color);
-                                               msg_debug ("got bgcolor: %xd", bl->background_color.d.val);
+                                               msg_debug_pool ("got bgcolor: %xd", bl->background_color.d.val);
                                        }
                                }
 
@@ -1535,19 +1535,19 @@ rspamd_html_process_block_tag (rspamd_mempool_t *pool, struct html_tag *tag,
                        fstr.begin = (gchar *)comp->start;
                        fstr.len = comp->len;
                        rspamd_html_process_color (comp->start, comp->len, &bl->font_color);
-                       msg_debug ("got color: %xd", bl->font_color.d.val);
+                       msg_debug_pool ("got color: %xd", bl->font_color.d.val);
                }
                else if (comp->type == RSPAMD_HTML_COMPONENT_STYLE && comp->len > 0) {
                        bl->style.len = comp->len;
                        bl->style.start =  comp->start;
-                       msg_debug ("got style: %*s", (gint)bl->style.len, bl->style.start);
+                       msg_debug_pool ("got style: %*s", (gint)bl->style.len, bl->style.start);
                        rspamd_html_process_style (pool, bl, hc, comp->start, comp->len);
                }
                else if (comp->type == RSPAMD_HTML_COMPONENT_CLASS && comp->len > 0) {
                        fstr.begin = (gchar *)comp->start;
                        fstr.len = comp->len;
                        bl->class = rspamd_mempool_fstrdup (pool, &fstr);
-                       msg_debug ("got class: %s", bl->class);
+                       msg_debug_pool ("got class: %s", bl->class);
                }
 
                cur = g_list_next (cur);
index 3ee2def4de83b3c087a86556a08b5135cde8a4ea..a1dabfab0c77037acaebc082ec5b862d0cf7001f 100644 (file)
@@ -355,7 +355,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'F':
                        if (g_ascii_strncasecmp (headern, FROM_HEADER, hlen) == 0) {
                                if (!rspamd_task_add_sender (task, hv->str)) {
-                                       msg_err ("bad from header: '%v'", hv);
+                                       msg_err_task ("bad from header: '%v'", hv);
                                        validh = FALSE;
                                }
                        }
@@ -395,7 +395,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'R':
                        if (g_ascii_strncasecmp (headern, RCPT_HEADER, hlen) == 0) {
                                if (!rspamd_task_add_recipient (task, hv->str)) {
-                                       msg_err ("bad from header: '%v'", h->value);
+                                       msg_err_task ("bad from header: '%v'", h->value);
                                        validh = FALSE;
                                }
                                debug_task ("read rcpt header, value: %v", hv);
@@ -409,7 +409,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                case 'I':
                        if (g_ascii_strncasecmp (headern, IP_ADDR_HEADER, hlen) == 0) {
                                if (!rspamd_parse_inet_address (&task->from_addr, hv->str)) {
-                                       msg_err ("bad ip header: '%v'", hv);
+                                       msg_err_task ("bad ip header: '%v'", hv);
                                        return FALSE;
                                }
                                debug_task ("read IP header, value: %v", hv);
@@ -482,7 +482,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                task->message_len = strtoul (hv->str, NULL, 10);
 
                                if (task->message_len == 0) {
-                                       msg_err ("Invalid message length header: %v", hv);
+                                       msg_err_task ("Invalid message length header: %v", hv);
                                        validh = FALSE;
                                }
                                else {
@@ -505,7 +505,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
        }
 
        if (!res && task->cfg->strict_protocol_headers) {
-               msg_err (
+               msg_err_task (
                        "deny processing of a request with incorrect or unknown headers");
                g_set_error (&task->err, rspamd_protocol_quark(), 400, "invalid header command");
                return FALSE;
@@ -620,7 +620,7 @@ rspamd_protocol_handle_control (struct rspamd_task *task,
 
        if (!rspamd_rcl_parse (control_parser, task, task->task_pool,
                        control, &err)) {
-               msg_warn ("cannot parse control block: %e", err);
+               msg_warn_task ("cannot parse control block: %e", err);
                g_error_free (err);
 
                return FALSE;
@@ -684,8 +684,9 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud)
        struct tree_cb_data *cb = ud;
        struct rspamd_url *url = value;
        ucl_object_t *obj, *elt;
+       struct rspamd_task *task = cb->task;
 
-       if (!(cb->task->flags & RSPAMD_TASK_FLAG_EXT_URLS)) {
+       if (!(task->flags & RSPAMD_TASK_FLAG_EXT_URLS)) {
                obj = ucl_object_fromlstring (url->host, url->hostlen);
        }
        else {
@@ -710,11 +711,11 @@ urls_protocol_cb (gpointer key, gpointer value, gpointer ud)
        ucl_array_append (cb->top, obj);
 
        if (cb->task->cfg->log_urls) {
-               msg_info ("<%s> URL: %s - %s: %s",
-                       cb->task->message_id,
-                       cb->task->user ?
-                       cb->task->user : "unknown",
-                       rspamd_inet_address_to_string (cb->task->from_addr),
+               msg_info_task ("<%s> URL: %s - %s: %s",
+                       task->message_id,
+                       task->user ?
+                       task->user : "unknown",
+                       rspamd_inet_address_to_string (task->from_addr),
                        struri (url));
        }
 }
@@ -1104,7 +1105,7 @@ rspamd_protocol_http_reply (struct rspamd_http_message *msg,
        }
 
        if (!(task->flags & RSPAMD_TASK_FLAG_NO_LOG)) {
-               msg_info ("%v", logbuf);
+               msg_info_task ("%v", logbuf);
        }
        g_string_free (logbuf, TRUE);
 
@@ -1146,7 +1147,7 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
        msg = rspamd_http_new_message (HTTP_RESPONSE);
 
        if (rspamd_http_connection_is_encrypted (task->http_conn)) {
-               msg_info ("<%s> writing encrypted reply", task->message_id);
+               msg_info_task ("<%s> writing encrypted reply", task->message_id);
        }
 
        if (!RSPAMD_TASK_IS_JSON (task)) {
@@ -1191,7 +1192,7 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
                        ctype = "text/plain";
                        break;
                case CMD_OTHER:
-                       msg_err ("BROKEN");
+                       msg_err_task ("BROKEN");
                        break;
                }
        }