diff --git a/doc/configuration.txt b/doc/configuration.txt index 9f553556f..05e8d22ca 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -26572,11 +26572,17 @@ log-profile log-tag Override syslog log tag set globally or per-proxy using "log-tag" directive. -on [format ] [sd ] +on [drop] [format ] [sd ] Override the log-format string normally used to build the log line at logging step. is used to override "log-format" or "error-log-format" strings (depending on the ) whereas is - used to override "log-format-sd" string. Possible values for are: + used to override "log-format-sd" string (both can be combined). + + "drop" special keyword may be used to specify that no log should be + emitted for the given . It takes precedence over "format" and + "sd" if previously defined. + + Possible values for are: - "accept" : override log-format if the log is generated right after frontend conn was accepted @@ -26604,6 +26610,7 @@ on [format ] [sd ] log-tag "custom-tag" on error format "%ci: error" + on connect drop on any sd "custom-sd" listen myproxy diff --git a/include/haproxy/log-t.h b/include/haproxy/log-t.h index 11161d241..0bc12b206 100644 --- a/include/haproxy/log-t.h +++ b/include/haproxy/log-t.h @@ -272,9 +272,16 @@ enum log_orig { LOG_ORIG_TXN_CLOSE, /* during stream termination */ }; +/* log profile step flags */ +enum log_ps_flags { + LOG_PS_FL_NONE = 0, + LOG_PS_FL_DROP, /* don't emit log for this step */ +}; + struct log_profile_step { struct lf_expr logformat; struct lf_expr logformat_sd; + enum log_ps_flags flags; /* LOG_PS_FL_* */ }; struct log_profile { diff --git a/reg-tests/log/log_profiles.vtc b/reg-tests/log/log_profiles.vtc index fc09639a1..552fb3243 100644 --- a/reg-tests/log/log_profiles.vtc +++ b/reg-tests/log/log_profiles.vtc @@ -66,6 +66,13 @@ syslog Slg3 -level info { barrier b4 sync } -start +syslog Slg4 -level info { + recv + #rfc5424, logprof3, tcp error (other steps should be dropped) + expect ~ ".* custom ${h1_pid} .* error" + barrier b4 sync +} -start + haproxy h1 -conf { defaults timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" @@ -92,6 +99,7 @@ haproxy h1 -conf { log udp@${Slg1_addr}:${Slg1_port} format rfc5424 local0 log udp@${Slg2_addr}:${Slg2_port} format rfc5424 profile logprof1 local0 log udp@${Slg3_addr}:${Slg3_port} format rfc5424 profile logprof2 local0 + log udp@${Slg4_addr}:${Slg4_port} format rfc5424 profile logprof3 local0 default_backend be_tcp @@ -119,6 +127,10 @@ haproxy h1 -conf { on error format "error" on any format "%OG" + log-profile logprof3 + on error format "error" + on any drop + backend be mode http server app1 ${s1_addr}:${s1_port} diff --git a/src/log.c b/src/log.c index fd8be525f..d338e1ec1 100644 --- a/src/log.c +++ b/src/log.c @@ -2927,6 +2927,9 @@ static inline void _process_send_log_override(struct process_send_log_ctx *ctx, step = prof->any; if (ctx && ctx->sess && step) { + if (step->flags & LOG_PS_FL_DROP) + goto end; // skip logging + /* we may need to rebuild message using lf_expr from profile * step and possibly sd metadata if provided on the profile */ @@ -6065,6 +6068,7 @@ static inline void log_profile_step_init(struct log_profile_step *lprof_step) { lf_expr_init(&lprof_step->logformat); lf_expr_init(&lprof_step->logformat_sd); + lprof_step->flags = LOG_PS_FL_NONE; } static inline void log_profile_step_free(struct log_profile_step *lprof_step) @@ -6285,14 +6289,24 @@ int cfg_parse_log_profile(const char *file, int linenum, char **args, int kwm) cur_arg = 2; while (*(args[cur_arg]) != 0) { + /* drop logs ? */ + if (strcmp(args[cur_arg], "drop") == 0) { + if (cur_arg != 2) + break; + (*target_step)->flags |= LOG_PS_FL_DROP; + cur_arg += 1; + continue; + } /* regular format or SD (structured-data) one? */ - if (strcmp(args[cur_arg], "format") == 0) + else if (strcmp(args[cur_arg], "format") == 0) target_lf = &(*target_step)->logformat; else if (strcmp(args[cur_arg], "sd") == 0) target_lf = &(*target_step)->logformat_sd; else break; + (*target_step)->flags &= ~LOG_PS_FL_DROP; + /* parse and assign logformat expression */ lf_expr_deinit(target_lf); /* if already configured */ @@ -6319,7 +6333,7 @@ int cfg_parse_log_profile(const char *file, int linenum, char **args, int kwm) cur_arg += 2; } if (cur_arg == 2 || *(args[cur_arg]) != 0) { - ha_alert("parsing [%s:%d] : '%s %s' expects 'format' and/or 'sd'.\n", + ha_alert("parsing [%s:%d] : '%s %s' expects 'drop', 'format' or 'sd'.\n", file, linenum, args[0], args[1]); err_code |= ERR_ALERT | ERR_FATAL; goto out;