mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: log: "drop" support for log-profile steps
It is now possible to use "drop" keyword for "on" lines under a log-profile section to specify that no log at all should be emitted for the specified step (setting an empty format was not sufficient to do so because only the log payload would be empty, not the log header, thus the log would still be emitted). It may be useful to selectively disable logging at specific steps for a given log target (since the log profile may be set on log directives): log-profile myprof on request format "blabla" sd "custom sd" on response drop New testcase was added to reg-tests/log/log_profiles.vtc
This commit is contained in:
parent
41ca89bc6f
commit
f8299bc5ea
@ -26572,11 +26572,17 @@ log-profile <name>
|
||||
log-tag <string>
|
||||
Override syslog log tag set globally or per-proxy using "log-tag" directive.
|
||||
|
||||
on <step> [format <fmt>] [sd <sd_fmt>]
|
||||
on <step> [drop] [format <fmt>] [sd <sd_fmt>]
|
||||
Override the log-format string normally used to build the log line at
|
||||
<step> logging step. <fmt> is used to override "log-format" or
|
||||
"error-log-format" strings (depending on the <step>) whereas <sd_fmt> is
|
||||
used to override "log-format-sd" string. Possible values for <step> 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 <step>. It takes precedence over "format" and
|
||||
"sd" if previously defined.
|
||||
|
||||
Possible values for <step> are:
|
||||
|
||||
- "accept" : override log-format if the log is generated right after
|
||||
frontend conn was accepted
|
||||
@ -26604,6 +26610,7 @@ on <step> [format <fmt>] [sd <sd_fmt>]
|
||||
log-tag "custom-tag"
|
||||
|
||||
on error format "%ci: error"
|
||||
on connect drop
|
||||
on any sd "custom-sd"
|
||||
|
||||
listen myproxy
|
||||
|
@ -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 {
|
||||
|
@ -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}
|
||||
|
18
src/log.c
18
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;
|
||||
|
Loading…
Reference in New Issue
Block a user