From a5555ec68a10f9e6755cbd374355d55caacf2268 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 30 Nov 2008 19:02:32 +0100 Subject: [PATCH] [MINOR] call session->do_log() for logging In order to avoid having to call per-protocol logging function directly from session.c, it's better to assign the logging function when the session is created. This also eliminates a test when the function is needed, and opens the way to more complete logging functions. --- include/types/session.h | 1 + src/client.c | 7 ++++++- src/proto_http.c | 9 +++------ src/session.c | 7 ++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/types/session.h b/include/types/session.h index a92949bc8..92bfa0626 100644 --- a/include/types/session.h +++ b/include/types/session.h @@ -188,6 +188,7 @@ struct session { long long bytes_in; /* number of bytes transferred from the client to the server */ long long bytes_out; /* number of bytes transferred from the server to the client */ } logs; + void (*do_log)(struct session *s); /* the function to call in order to log */ short int data_source; /* where to get the data we generate ourselves */ short int data_state; /* where to get the data we generate ourselves */ union { diff --git a/src/client.c b/src/client.c index 78387a154..8e8dc53f8 100644 --- a/src/client.c +++ b/src/client.c @@ -206,6 +206,11 @@ int event_accept(int fd) { else s->logs.logwait = p->to_log; + if (s->logs.logwait & LW_REQ) + s->do_log = http_sess_log; + else + s->do_log = tcp_sess_log; + s->logs.accept_date = date; /* user-visible date for logging */ s->logs.tv_accept = now; /* corrected date for internal use */ tv_zero(&s->logs.tv_request); @@ -276,7 +281,7 @@ int event_accept(int fd) { /* we have the client ip */ if (s->logs.logwait & LW_CLIP) if (!(s->logs.logwait &= ~LW_CLIP)) - tcp_sess_log(s); + s->do_log(s); } else if (s->cli_addr.ss_family == AF_INET) { char pn[INET_ADDRSTRLEN], sn[INET_ADDRSTRLEN]; diff --git a/src/proto_http.c b/src/proto_http.c index 7bc9fa6d5..b14322eb9 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -1858,7 +1858,7 @@ int process_request(struct session *t) client_retnclose(t, &http_200_chunk); goto return_prx_cond; } - + /* * 3: Maybe we have to copy the original REQURI for the logs ? * Note: we cannot log anymore if the request has been @@ -1875,7 +1875,7 @@ int process_request(struct session *t) txn->uri[urilen] = 0; if (!(t->logs.logwait &= ~LW_REQ)) - http_sess_log(t); + t->do_log(t); } else { Alert("HTTP logging : out of memory.\n"); } @@ -3058,10 +3058,7 @@ int process_response(struct session *t) if (t->fe->to_log && !(t->logs.logwait & LW_BYTES)) { t->logs.t_close = t->logs.t_data; /* to get a valid end date */ t->logs.bytes_out = txn->rsp.eoh; - if (t->fe->to_log & LW_REQ) - http_sess_log(t); - else - tcp_sess_log(t); + t->do_log(t); t->logs.bytes_out = 0; } diff --git a/src/session.c b/src/session.c index 75cc3f389..1eb7b69fc 100644 --- a/src/session.c +++ b/src/session.c @@ -321,7 +321,7 @@ void sess_establish(struct session *s, struct stream_interface *si) * bytes from the server, then this is the right moment. */ if (s->fe->to_log && !(s->logs.logwait & LW_BYTES)) { s->logs.t_close = s->logs.t_connect; /* to get a valid end date */ - tcp_sess_log(s); + s->do_log(s); } #ifdef CONFIG_HAP_TCPSPLICE if ((s->fe->options & s->be->options) & PR_O_TCPSPLICE) { @@ -965,10 +965,7 @@ resync_stream_interface: if (s->logs.logwait && !(s->flags & SN_MONITOR) && (!(s->fe->options & PR_O_NULLNOLOG) || s->req->total)) { - if (s->fe->to_log & LW_REQ) - http_sess_log(s); - else - tcp_sess_log(s); + s->do_log(s); } /* the task MUST not be in the run queue anymore */