Skip to content

Commit

Permalink
lib-http: client: Added identifier to client log messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and cmouse committed Dec 7, 2017
1 parent faa4f87 commit fd30e54
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/lib-http/http-client-connection.c
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib-http/http-client-host.c
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib-http/http-client-peer.c
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib-http/http-client-private.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib-http/http-client-queue.c
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib-http/http-client-request.c
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib-http/http-client.c
Expand Up @@ -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;

Expand All @@ -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 */
Expand Down

0 comments on commit fd30e54

Please sign in to comment.