[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.
This commit is contained in:
Willy Tarreau 2011-02-13 14:30:26 +01:00
parent 7c0a151a2e
commit 71904a4ee8
2 changed files with 42 additions and 9 deletions

View File

@ -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 : "<NOSRV>" : "-";
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 = "<NOSRV>";
break;
}
level = LOG_INFO;
if (err && (fe->options2 & PR_O2_LOGERRORS))

View File

@ -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 : "<NOSRV>" : "<STATS>" : "-";
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 = "<NOSRV>";
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 : "<NOSRV>" : "<STATS>" : "-";
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 = "<NOSRV>";
break;
}
t_request = -1;
if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))