From: Willy Tarreau Date: Tue, 11 Jun 2013 15:18:02 +0000 (+0200) Subject: MEDIUM: log: add a log level override value in struct session X-Git-Tag: v1.5-dev19~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abcd5145f82cff7beb6b1b25b90a8266d672a6f7;p=thirdparty%2Fhaproxy.git MEDIUM: log: add a log level override value in struct session This log level will be used in a further patch to change the log level depending on the request or response. --- diff --git a/include/types/session.h b/include/types/session.h index b6bff5753f..efdcaa6912 100644 --- a/include/types/session.h +++ b/include/types/session.h @@ -151,6 +151,7 @@ struct session { struct stream_interface si[2]; /* client and server stream interfaces */ struct { int logwait; /* log fields waiting to be collected : LW_* */ + int level; /* log level to force + 1 if > 0, -1 = no log */ struct timeval accept_date; /* date of the accept() in user date */ struct timeval tv_accept; /* date of the accept() in internal date (monotonic) */ struct timeval tv_request; /* date the request arrives, {0,0} if never occurs */ diff --git a/src/log.c b/src/log.c index 627351f357..8f8fd8f8c4 100644 --- a/src/log.c +++ b/src/log.c @@ -1528,9 +1528,18 @@ void sess_log(struct session *s) if (LIST_ISEMPTY(&s->fe->logsrvs)) return; - level = LOG_INFO; - if (err && (s->fe->options2 & PR_O2_LOGERRORS)) - level = LOG_ERR; + if (s->logs.level) { /* loglevel was overridden */ + if (s->logs.level == -1) { + s->logs.logwait = 0; /* logs disabled */ + return; + } + level = s->logs.level - 1; + } + else { + level = LOG_INFO; + if (err && (s->fe->options2 & PR_O2_LOGERRORS)) + level = LOG_ERR; + } tmplog = update_log_hdr(); size = tmplog - logline; diff --git a/src/peers.c b/src/peers.c index 61fb938a3f..998e61daca 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1185,6 +1185,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio */ s->logs.logwait = 0; + s->logs.level = 0; s->do_log = NULL; /* default error reporting function, may be changed by analysers */ diff --git a/src/proto_http.c b/src/proto_http.c index ed6c90b055..de9b331300 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -2528,6 +2528,7 @@ int http_wait_for_request(struct session *s, struct channel *req, int an_bit) msg->msg_state = HTTP_MSG_RQBEFORE; req->analysers = 0; s->logs.logwait = 0; + s->logs.level = 0; s->rep->flags &= ~CF_EXPECT_MORE; /* speed up sending a previous response */ stream_int_retnclose(req->prod, NULL); return 0; @@ -8315,6 +8316,7 @@ void http_reset_txn(struct session *s) s->be = s->fe; s->logs.logwait = s->fe->to_log; + s->logs.level = 0; session_del_srv_conn(s); s->target = NULL; /* re-init store persistence */