]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: explicitly handle extra log origins as error when relevant
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 31 Jul 2024 12:10:52 +0000 (14:10 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 26 Sep 2024 14:53:07 +0000 (16:53 +0200)
Thanks to previous commit, we can know check for log_orig optional flags
in functions taking struct log_orig as parameter. Let's take this
opportunity to add the LOG_ORIG_FL_ERROR flag and check this flag at a
few places to handle the log message differently because if the flag is
set then the caller expects the log to be handled as an error explicitly.

e.g.: in _process_send_log_override(), if the flag is set, use the error
log format instead of the dedicated one.

include/haproxy/log-t.h
src/log.c

index 2a4eb4df58dab3449503525f414ef9b5383432a3..2bcb2ddc4bff6462345eecbdc97f7c1880f4d06c 100644 (file)
@@ -280,6 +280,7 @@ enum log_orig_id {
 /* log orig flags
  */
 #define LOG_ORIG_FL_NONE  0x0000
+#define LOG_ORIG_FL_ERROR 0x0001
 #define LOG_ORIG_FL_ALL   0xFFFF
 
 struct log_orig {
index 69c3411dc8d58d587d33ef6ef1c873e1ec735e43..38b02edb61438b670dc7ed0c872a914ff71d6e05 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2896,6 +2896,7 @@ static inline void _process_send_log_override(struct process_send_log_ctx *ctx,
        struct ist orig_tag = hdr.metadata[LOG_META_TAG];
        struct ist orig_sd = hdr.metadata[LOG_META_STDATA];
        enum log_orig_id orig = (ctx) ? ctx->origin.id : LOG_ORIG_UNSPEC;
+       uint16_t orig_fl = (ctx) ? ctx->origin.flags : LOG_ORIG_FL_NONE;
 
        BUG_ON(!prof);
 
@@ -2936,6 +2937,13 @@ static inline void _process_send_log_override(struct process_send_log_ctx *ctx,
                        struct log_profile_step_extra *extra;
 
                        /* catchall for extra log origins */
+                       if ((orig_fl & LOG_ORIG_FL_ERROR) && prof->error) {
+                               /* extra orig with explicit error flag, must be
+                                * handled as an error
+                                */
+                               step = prof->error;
+                               break;
+                       }
 
                        /* check if there is a log step defined for this log origin */
                        extra = container_of_safe(eb32_lookup(&prof->extra, orig),
@@ -5150,7 +5158,8 @@ void strm_log(struct stream *s, struct log_orig origin)
        err = (s->flags & SF_REDISP) ||
               ((s->flags & SF_ERR_MASK) > SF_ERR_LOCAL) ||
              (((s->flags & SF_ERR_MASK) == SF_ERR_NONE) && s->conn_retries) ||
-             ((sess->fe->mode == PR_MODE_HTTP) && s->txn && s->txn->status >= 500);
+             ((sess->fe->mode == PR_MODE_HTTP) && s->txn && s->txn->status >= 500) ||
+             (origin.flags & LOG_ORIG_FL_ERROR);
 
        if (!err && (sess->fe->options2 & PR_O2_NOLOGNORM))
                return;