]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] call session->do_log() for logging
authorWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 18:02:32 +0000 (19:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 18:02:32 +0000 (19:02 +0100)
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
src/client.c
src/proto_http.c
src/session.c

index a92949bc85dfff0763f18360dfc0726355570170..92bfa0626dbc06cb706c93ff82f77a325f7725d8 100644 (file)
@@ -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 {
index 78387a1544f7201a605a6afe8f499f9832a872fd..8e8dc53f8944bb638e1fae25ba02ca7513fae3f0 100644 (file)
@@ -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];
index 7bc9fa6d5fc309e1b5b875e4e70d8db2af33afed..b14322eb9a6c0a6646926a1d5d5e304a8a7ee594 100644 (file)
@@ -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;
                }
 
index 75cc3f3895713442c93ce8300390527159ceab88..1eb7b69fc5e43d0655273f6ad0ef7f6a8f9f7663 100644 (file)
@@ -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 */