diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 8d7b50868..eef7654f5 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -87,7 +87,20 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t * Will not log if the frontend has no log defined. */ void strm_log(struct stream *s); -void sess_log(struct session *sess); + +/* send an error log for the session, embryonic version should be used + * when the log is emitted for a session which is still in embryonic state + * (originating from a connection) and requires special handling. + */ +void _sess_log(struct session *sess, int embryonic); +static inline void sess_log(struct session *sess) +{ + _sess_log(sess, 0); +} +static inline void sess_log_embryonic(struct session *sess) +{ + _sess_log(sess, 1); +} /* send a applicative log with custom list of loggers */ void app_log(struct list *loggers, struct buffer *tag, int level, const char *format, ...) diff --git a/src/log.c b/src/log.c index 052fc07e1..189bfbd9c 100644 --- a/src/log.c +++ b/src/log.c @@ -4947,8 +4947,12 @@ void strm_log(struct stream *s) * in the frontend. The caller must simply know that it should not call this * function to report unimportant events. It is safe to call this function with * sess==NULL (will not do anything). + * + * if is set, then legacy error log payload will be generated unless + * logformat_error is specified (ie: normal logformat is ignored in this case). + * */ -void sess_log(struct session *sess) +void _sess_log(struct session *sess, int embryonic) { int size, level; int sd_size = 0; @@ -4971,8 +4975,15 @@ void sess_log(struct session *sess) if (!lf_expr_isempty(&sess->fe->logformat_error)) size = sess_build_logline(sess, NULL, logline, global.max_syslog_len, &sess->fe->logformat_error); - else + else if (!embryonic) size = sess_build_logline(sess, NULL, logline, global.max_syslog_len, &sess->fe->logformat); + else { /* no logformat_error and embryonic==1 */ + struct buffer buf; + + buf = b_make(logline, global.max_syslog_len, 0, 0); + session_embryonic_build_legacy_err(sess, &buf); + size = buf.data; + } if (size > 0) { _HA_ATOMIC_INC(&sess->fe->log_count); __send_log(&sess->fe->loggers, &sess->fe->log_tag, level, diff --git a/src/session.c b/src/session.c index f8e6ea9f1..016e47120 100644 --- a/src/session.c +++ b/src/session.c @@ -422,14 +422,10 @@ void session_embryonic_build_legacy_err(struct session *sess, struct buffer *out */ static void session_kill_embryonic(struct session *sess, unsigned int state) { - int level = LOG_INFO; struct connection *conn = __objt_conn(sess->origin); struct task *task = sess->task; unsigned int log = sess->fe->to_log; - if (sess->fe->options2 & PR_O2_LOGERRORS) - level = LOG_ERR; - if (log && (sess->fe->options & PR_O_NULLNOLOG)) { /* with "option dontlognull", we don't log connections with no transfer */ if (!conn->err_code || @@ -449,14 +445,7 @@ static void session_kill_embryonic(struct session *sess, unsigned int state) conn->err_code = CO_ER_SSL_TIMEOUT; } - if(!lf_expr_isempty(&sess->fe->logformat_error)) { - /* Display a log line following the configured error-log-format. */ - sess_log(sess); - } - else { - session_embryonic_build_legacy_err(sess, &trash); - send_log(sess->fe, level, "%s", trash.area); - } + sess_log_embryonic(sess); } /* kill the connection now */