From: Aurelien DARRAGON Date: Wed, 31 Jul 2024 12:10:52 +0000 (+0200) Subject: MINOR: log: explicitly handle extra log origins as error when relevant X-Git-Tag: v3.1-dev9~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8bb9d5c5746e9fec48ca5c60ec9ebbdf4ee16ba;p=thirdparty%2Fhaproxy.git MINOR: log: explicitly handle extra log origins as error when relevant 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. --- diff --git a/include/haproxy/log-t.h b/include/haproxy/log-t.h index 2a4eb4df58..2bcb2ddc4b 100644 --- a/include/haproxy/log-t.h +++ b/include/haproxy/log-t.h @@ -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 { diff --git a/src/log.c b/src/log.c index 69c3411dc8..38b02edb61 100644 --- 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;