]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: log/session: handle embryonic session log within sess_log()
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 21 Feb 2024 16:26:52 +0000 (17:26 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 13 Jun 2024 13:43:09 +0000 (15:43 +0200)
Move the embryonic session logging logic down to sess_log() in preparation
for log-profiles because then log preferences will be set per logger and
not per proxy. Indeed, as each logger may come with its own log-profile
that possibly overrides proxy logformat preferences, the check will need
to be performed at a central place by lower sending functions.

To ensure the change doesn't break existing behavior, a dedicated
sess_log_embryonic() wrapper was added and is exclusively used by
session_kill_embryonic() to indicate that a special logging logic must
be performed under sess_log().

Also, thanks to this change, log-format-sd will now be taken into account
for legacy embryonic session logging.

include/haproxy/log.h
src/log.c
src/session.c

index 8d7b508688b018bd2f2cf9810b13ffaf6410ae16..eef7654f519a208bdb3161a1c91e435df96fd023 100644 (file)
@@ -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, ...)
index 052fc07e1431f0ec9f817a827511f4b40dbc856f..189bfbd9cdde626f66a1be299a7342a8b9b7ee92 100644 (file)
--- 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 <embryonic> 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,
index f8e6ea9f10083a95a9ccf7ffd9c1932f3a236e46..016e47120f2be9426092b37e025f25c1d3b7480d 100644 (file)
@@ -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 */