From fd30e54bd56f0869f5c2e14b42fd53f7b36cff45 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Sun, 4 Dec 2016 21:54:02 +0100 Subject: [PATCH] lib-http: client: Added identifier to client log messages. --- src/lib-http/http-client-connection.c | 8 +++++++- src/lib-http/http-client-host.c | 2 +- src/lib-http/http-client-peer.c | 4 ++-- src/lib-http/http-client-private.h | 1 + src/lib-http/http-client-queue.c | 2 +- src/lib-http/http-client-request.c | 2 +- src/lib-http/http-client.c | 4 ++++ 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index 3d48053cc6..8273c8645f 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -30,11 +30,17 @@ static inline void http_client_connection_debug(struct http_client_connection *conn, const char *format, ...) { + const char *log_prefix; va_list args; + if (conn->peer != NULL) + log_prefix = conn->peer->client->log_prefix; + else + log_prefix = "http-client: "; + if (conn->debug || conn->ppool->peer->cctx->set.debug) { va_start(args, format); - i_debug("http-client: conn %s: %s", + i_debug("%sconn %s: %s", log_prefix, conn->label, t_strdup_vprintf(format, args)); va_end(args); } diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 04b313aa59..fed2d81070 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -59,7 +59,7 @@ http_client_host_debug(struct http_client_host *host, if (host->client->set.debug) { va_start(args, format); - i_debug("http-client: host %s: %s", + i_debug("%shost %s: %s", host->client->log_prefix, host->shared->name, t_strdup_vprintf(format, args)); va_end(args); } diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index 302b6873a7..3c5cf63a4d 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -88,8 +88,8 @@ http_client_peer_debug(struct http_client_peer *peer, va_list args; if (client->set.debug) { - va_start(args, format); - i_debug("http-client: peer %s: %s", + va_start(args, format); + i_debug("%speer %s: %s", client->log_prefix, http_client_peer_shared_label(pshared), t_strdup_vprintf(format, args)); va_end(args); } diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 8a93ef1000..efbb6d136a 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -356,6 +356,7 @@ struct http_client { pool_t pool; struct http_client_context *cctx; struct http_client_settings set; + const char *log_prefix; struct ioloop *ioloop; struct ssl_iostream_context *ssl_ctx; diff --git a/src/lib-http/http-client-queue.c b/src/lib-http/http-client-queue.c index ebc662c657..83135ab170 100644 --- a/src/lib-http/http-client-queue.c +++ b/src/lib-http/http-client-queue.c @@ -46,7 +46,7 @@ http_client_queue_debug(struct http_client_queue *queue, // FIXME: find some other method of distinguishing clients va_start(args, format); - i_debug("http-client: queue %s: %s", + i_debug("%squeue %s: %s", queue->client->log_prefix, queue->name, t_strdup_vprintf(format, args)); va_end(args); } diff --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index 4a1d0689b2..a5b2e1b76e 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -46,7 +46,7 @@ http_client_request_debug(struct http_client_request *req, if (req->client->set.debug) { va_start(args, format); - i_debug("http-client: request %s: %s", + i_debug("%srequest %s: %s", req->client->log_prefix, http_client_request_label(req), t_strdup_vprintf(format, args)); va_end(args); } diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index 9d8ee50b6f..299694ef24 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -88,6 +88,7 @@ struct http_client * http_client_init_shared(struct http_client_context *cctx, const struct http_client_settings *set) { + static unsigned int id = 0; struct http_client *client; pool_t pool; @@ -96,11 +97,14 @@ http_client_init_shared(struct http_client_context *cctx, client->pool = pool; /* create private context if none is provided */ + id++; if (cctx != NULL) { client->cctx = cctx; http_client_context_ref(cctx); + client->log_prefix = p_strdup_printf(pool, "http-client[%u]: ", id); } else { client->cctx = cctx = http_client_context_create(set); + client->log_prefix = "http-client: "; } /* merge provided settings with context defaults */