]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connection: Add option to disable legacy error log
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Thu, 29 Jul 2021 07:45:53 +0000 (09:45 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Thu, 29 Jul 2021 13:40:45 +0000 (15:40 +0200)
In case of connection failure, a dedicated error message is output,
following the format described in section "Error log format" of the
documentation. These messages cannot be configured through a log-format
option.
This patch adds a new option, "dontloglegacyconnerr", that disables
those error logs when set, and "replaces" them by a regular log line
that follows the configured log-format (thanks to a call to sess_log in
session_kill_embryonic).
The new fc_conn_err sample fetch allows to add the legacy error log
information into a regular log format.
This new option is unset by default so the logging logic will remain the
same until this new option is used.

doc/configuration.txt
include/haproxy/proxy-t.h
src/proxy.c
src/session.c

index 710d8112a4dffc5508da55c9ea3f9a2007d45604..6ecf7bcfe47d0e95414000c011acc42fafde432c 100644 (file)
@@ -9033,6 +9033,23 @@ no option logasap
              logging.
 
 
+option dontloglegacyconnerr
+no option dontloglegacyconnerr
+  Enable or disable dedicated connection error logging.
+  May be used in sections :   defaults | frontend | listen | backend
+                                 yes   |    yes   |   yes  |   no
+  Arguments : none
+
+  In case of connection error, if the option is disabled, a log line following
+  the format described in section 8.2.6, the legacy format, will be emitted.
+  Otherwise, a log line following the configured log-format for the listener
+  will be emitted. The error code and the corresponding message found in the
+  error log can be added to a log-format thanks to the "fc_conn_err" and
+  "fc_conn_err_str" sample fetches.
+
+  See also : "option httpslog" and section 8 about logging.
+
+
 option mysql-check [ user <username> [ { post-41 | pre-41 } ] ]
   Use MySQL health checks for server testing
   May be used in sections :   defaults | frontend | listen | backend
@@ -20984,7 +21001,9 @@ protocol header, HAProxy will log the event using a shorter, fixed line format.
 By default, logs are emitted at the LOG_INFO level, unless the option
 "log-separate-errors" is set in the backend, in which case the LOG_ERR level
 will be used. Connections on which no data are exchanged (e.g. probes) are not
-logged if the "dontlognull" option is set.
+logged if the "dontlognull" option is set. If the "dontloglegacyconnerr" option
+is set, those messages are not emitted and a line following the configured
+log-format is emitted instead.
 
 The format looks like this :
 
index ba6a5fa4cff3b33416849a3641bdb1fc2c3b0415..47571e8955c556e436839d75ff58649afee34b41 100644 (file)
@@ -95,7 +95,8 @@ enum PR_SRV_STATE_FILE {
 #define PR_O_FF_ALWAYS  0x00002000      /* always set x-forwarded-for */
 #define PR_O_PERSIST    0x00004000      /* server persistence stays effective even when server is down */
 #define PR_O_LOGASAP    0x00008000      /* log as soon as possible, without waiting for the stream to complete */
-/* unused: 0x00010000 */
+#define PR_O_NOLGCYCONNERR 0x00010000   /* log a dedicated error log message in case of connection failure instead of the legacy connection error message */
+
 #define PR_O_CHK_CACHE  0x00020000      /* require examination of cacheability of the 'set-cookie' field */
 #define PR_O_TCP_CLI_KA 0x00040000      /* enable TCP keep-alive on client-side streams */
 #define PR_O_TCP_SRV_KA 0x00080000      /* enable TCP keep-alive on server-side streams */
index fc5371f69b6efa273f99b08fb74be97bf25326f8..63546d2d3b5fc588693cffa631538da8b4422e65 100644 (file)
@@ -72,6 +72,7 @@ const struct cfg_opt cfg_opts[] =
        { "http-ignore-probes", PR_O_IGNORE_PRB, PR_CAP_FE, 0, PR_MODE_HTTP },
        { "prefer-last-server", PR_O_PREF_LAST,  PR_CAP_BE, 0, PR_MODE_HTTP },
        { "logasap",      PR_O_LOGASAP,    PR_CAP_FE, 0, 0 },
+       { "dontloglegacyconnerr", PR_O_NOLGCYCONNERR, PR_CAP_FE, 0, 0 },
        { "nolinger",     PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0, 0 },
        { "persist",      PR_O_PERSIST,    PR_CAP_BE, 0, 0 },
        { "srvtcpka",     PR_O_TCP_SRV_KA, PR_CAP_BE, 0, 0 },
index 4789ca972199e63e4b64f7ba1d330e6c436ffe80..8b830639fe298145c8d7a05eff736e13b48028ac 100644 (file)
@@ -357,14 +357,20 @@ static void session_kill_embryonic(struct session *sess, unsigned int state)
                                conn->err_code = CO_ER_SSL_TIMEOUT;
                }
 
-               session_prepare_log_prefix(sess);
-               err_msg = conn_err_code_str(conn);
-               if (err_msg)
-                       send_log(sess->fe, level, "%s: %s\n", trash.area,
-                                err_msg);
-               else
-                       send_log(sess->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n",
-                                trash.area, conn->err_code, conn->flags);
+               if (sess->fe->options & PR_O_NOLGCYCONNERR) {
+                       /* Display a log line following the configured log-format. */
+                       sess_log(sess);
+               }
+               else {
+                       session_prepare_log_prefix(sess);
+                       err_msg = conn_err_code_str(conn);
+                       if (err_msg)
+                               send_log(sess->fe, level, "%s: %s\n", trash.area,
+                                        err_msg);
+                       else
+                               send_log(sess->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n",
+                                        trash.area, conn->err_code, conn->flags);
+               }
        }
 
        /* kill the connection now */