From: Aurelien DARRAGON Date: Tue, 30 Jan 2024 17:01:15 +0000 (+0100) Subject: MINOR: log: print metadata prefixes separately in sess_build_logline() X-Git-Tag: v3.0-dev4~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8d2b9e2acddf354581c694928d05b9f468d501fd;p=thirdparty%2Fhaproxy.git MINOR: log: print metadata prefixes separately in sess_build_logline() Some log variables may be prefixed with specific chars that represent extra informations that are relevant with it but are are not directly part of the "raw" value. ie: '+' char is prepended before some values when "option logasap" is used to indicate that the value has not yet reached its final value. However, as those "metadata" are printed using the general purpose LOGCHAR() printing helper, it's not easy to tell if they are part of the base value or not. In this patch we add the LOGMETACHAR() helper that is a wrapper for LOGCHAR(). The goal is to prepare for adding some logic to prevent such additional infos from being generated when not relevant or needed. --- diff --git a/src/log.c b/src/log.c index e169dd401b..c211fe5200 100644 --- a/src/log.c +++ b/src/log.c @@ -2536,6 +2536,14 @@ const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found a } \ } while (0) +/* Prints additional logvalue hint represented by . + * It is useful to express that is not part of the "raw" value and + * should be considered as optional metadata instead. + */ +#define LOGMETACHAR(chr) do { \ + LOGCHAR(chr); \ + } while (0) + /* Initializes some log data at boot */ static void init_log() { @@ -3160,7 +3168,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_Ta: // %Ta = active time = Tt - Th - Ti if (!(fe->to_log & LW_BYTES)) - LOGCHAR('+'); + LOGMETACHAR('+'); ret = ltoa_o(logs->t_close - (logs->t_idle >= 0 ? logs->t_idle + logs->t_handshake : 0), tmplog, dst + maxsize - tmplog); if (ret == NULL) @@ -3170,7 +3178,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_TT: // %Tt = total time if (!(fe->to_log & LW_BYTES)) - LOGCHAR('+'); + LOGMETACHAR('+'); ret = ltoa_o(logs->t_close, tmplog, dst + maxsize - tmplog); if (ret == NULL) goto out; @@ -3179,7 +3187,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_TU: // %Tu = total time seen by user = Tt - Ti if (!(fe->to_log & LW_BYTES)) - LOGCHAR('+'); + LOGMETACHAR('+'); ret = ltoa_o(logs->t_close - (logs->t_idle >= 0 ? logs->t_idle : 0), tmplog, dst + maxsize - tmplog); if (ret == NULL) @@ -3196,7 +3204,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_BYTES: // %B if (!(fe->to_log & LW_BYTES)) - LOGCHAR('+'); + LOGMETACHAR('+'); ret = lltoa(logs->bytes_out, tmplog, dst + maxsize - tmplog); if (ret == NULL) goto out; @@ -3283,7 +3291,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_RETRIES: // %rc if (s_flags & SF_REDISP) - LOGCHAR('+'); + LOGMETACHAR('+'); ret = ltoa_o((s ? s->conn_retries : 0), tmplog, dst + maxsize - tmplog); if (ret == NULL) goto out;