]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: log: add proxy_logformat_origin() to detect a proxy's log-format type
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2026 16:42:16 +0000 (18:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2026 08:30:59 +0000 (10:30 +0200)
This new function will check the proxy's logformat.str and return return
an option name (e.g. "option httplog") or a directive ("log-format") that
will permit error messages to report where a log-format had been set.

include/haproxy/log.h

index 79330e0f0ca655c1cdcc7ee4b85f83e0ea07c0de..0dbbae3eb1a7181f158915226bca0b35d0f65cbf 100644 (file)
@@ -246,6 +246,25 @@ static inline struct proxy *log_forward_by_name(const char *name)
        return NULL;
 }
 
+/* Returns the name of the directive which assigned the proxy's current log
+ * format, for use in the warning emitted when it is overridden. Defaults to
+ * "log-format" for a format which is not one of the built-in ones.
+ */
+static inline const char *proxy_logformat_origin(const struct proxy *px)
+{
+       if (px->logformat.str == default_http_log_format)
+               return "option httplog";
+       if (px->logformat.str == default_tcp_log_format)
+               return "option tcplog";
+       if (px->logformat.str == clf_tcp_log_format)
+               return "option tcplog clf";
+       if (px->logformat.str == clf_http_log_format)
+               return "option httplog clf";
+       if (px->logformat.str == default_https_log_format)
+               return "option httpslog";
+       return "log-format";
+}
+
 #endif /* _HAPROXY_LOG_H */
 
 /*