From: Willy Tarreau Date: Sun, 13 Feb 2011 13:30:26 +0000 (+0100) Subject: [MEDIUM] log: take the logged server name from the stream interface X-Git-Tag: v1.5-dev8~293 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71904a4ee871ffb0c9a98506545d45441328c7a9;p=thirdparty%2Fhaproxy.git [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. --- diff --git a/src/log.c b/src/log.c index b366d3bf0e..de1bf2fbfc 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 9693ad8b25..7830580fa3 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))