From 71904a4ee871ffb0c9a98506545d45441328c7a9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 13 Feb 2011 14:30:26 +0100 Subject: [PATCH] [MEDIUM] log: take the logged server name from the stream interface With HTTP keep-alive, logging the right server name will be quite complex because the assigned server will possibly change before we log. Also, when we want to log accesses to an applet, it's not easy because the applet becomes NULL again before logging. The logged server's name is now taken from the target stored in the stream interface. That way we can log an applet, a server name, or we could even log a proxy or anything else if we wanted to. Ideally the session should contain a desired target which is the one which should be logged. --- src/log.c | 15 ++++++++++++++- src/proto_http.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/log.c b/src/log.c index b366d3bf0..de1bf2fbf 100644 --- a/src/log.c +++ b/src/log.c @@ -348,7 +348,20 @@ void tcp_sess_log(struct session *s) prx_log = fe; tolog = fe->to_log; - svid = (tolog & LW_SVID) ? (s->srv != NULL) ? s->srv->id : "" : "-"; + + if (!(tolog & LW_SVID)) + svid = "-"; + else switch (s->req->cons->target.type) { + case TARG_TYPE_SERVER: + svid = s->req->cons->target.ptr.s->id; + break; + case TARG_TYPE_APPLET: + svid = s->req->cons->target.ptr.a->name; + break; + default: + svid = ""; + break; + } level = LOG_INFO; if (err && (fe->options2 & PR_O2_LOGERRORS)) diff --git a/src/proto_http.c b/src/proto_http.c index 9693ad8b2..7830580fa 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -855,7 +855,7 @@ void http_sess_clflog(struct session *s) struct http_txn *txn = &s->txn; int tolog, level, err; char *uri, *h; - char *svid; + const char *svid; struct tm tm; static char tmpline[MAX_SYSLOG_LEN]; int hdr; @@ -943,9 +943,19 @@ void http_sess_clflog(struct session *s) h += w; *(h++) = '\"'; - svid = (tolog & LW_SVID) ? - (s->data_source != DATA_SRC_STATS) ? - (s->srv != NULL) ? s->srv->id : "" : "" : "-"; + if (!(tolog & LW_SVID)) + svid = "-"; + else switch (s->req->cons->target.type) { + case TARG_TYPE_SERVER: + svid = s->req->cons->target.ptr.s->id; + break; + case TARG_TYPE_APPLET: + svid = s->req->cons->target.ptr.a->name; + break; + default: + svid = ""; + break; + } w = strlen(svid); if (h >= tmpline + sizeof(tmpline) - 4 - w) @@ -1081,7 +1091,7 @@ void http_sess_log(struct session *s) struct http_txn *txn = &s->txn; int tolog, level, err; char *uri, *h; - char *svid; + const char *svid; struct tm tm; static char tmpline[MAX_SYSLOG_LEN]; int t_request; @@ -1156,9 +1166,19 @@ void http_sess_log(struct session *s) } *h = '\0'; - svid = (tolog & LW_SVID) ? - (s->data_source != DATA_SRC_STATS) ? - (s->srv != NULL) ? s->srv->id : "" : "" : "-"; + if (!(tolog & LW_SVID)) + svid = "-"; + else switch (s->req->cons->target.type) { + case TARG_TYPE_SERVER: + svid = s->req->cons->target.ptr.s->id; + break; + case TARG_TYPE_APPLET: + svid = s->req->cons->target.ptr.a->name; + break; + default: + svid = ""; + break; + } t_request = -1; if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))