From a1f12746b12d7982972b775672e5d119c8b60f10 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 1 Dec 2020 09:46:46 +0100 Subject: [PATCH] MINOR: traces: add a new level "error" below the "user" level Sometimes it would be nice to be able to only trace abnormal events such as protocol errors. Let's add a new "error" level below the "user" level for this. This will allow to add TRACE_ERROR() at various error points and only see them. --- include/haproxy/trace-t.h | 3 ++- include/haproxy/trace.h | 5 +++++ src/trace.c | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/haproxy/trace-t.h b/include/haproxy/trace-t.h index 8bc7d0070c..953a0b9958 100644 --- a/include/haproxy/trace-t.h +++ b/include/haproxy/trace-t.h @@ -79,7 +79,8 @@ enum trace_state { * lower level are always reported at higher levels. */ enum trace_level { - TRACE_LEVEL_USER = 0, // info useful to the end user + TRACE_LEVEL_ERROR = 0, // only errors + TRACE_LEVEL_USER, // also info useful to the end user TRACE_LEVEL_PROTO, // also report protocol-level updates TRACE_LEVEL_STATE, // also report state changes TRACE_LEVEL_DATA, // also report data exchanges diff --git a/include/haproxy/trace.h b/include/haproxy/trace.h index f200ef1143..25f0831a6b 100644 --- a/include/haproxy/trace.h +++ b/include/haproxy/trace.h @@ -53,6 +53,9 @@ #define TRACE(msg, mask, args...) \ trace(TRACE_LEVEL, (mask), TRACE_SOURCE, ist(TRC_LOC), NULL, TRC_5ARGS(0,##args,0,0,0,0,0), ist(msg)) +#define TRACE_ERROR(msg, mask, args...) \ + trace(TRACE_LEVEL_ERROR, (mask), TRACE_SOURCE, ist(TRC_LOC), NULL, TRC_5ARGS(0,##args,0,0,0,0,0), ist(msg)) + #define TRACE_USER(msg, mask, args...) \ trace(TRACE_LEVEL_USER, (mask), TRACE_SOURCE, ist(TRC_LOC), NULL, TRC_5ARGS(0,##args,0,0,0,0,0), ist(msg)) @@ -79,6 +82,7 @@ #if defined(DEBUG_DEV) || defined(DEBUG_FULL) # define DBG_TRACE(msg, mask, args...) TRACE(msg, mask, ##args) +# define DBG_TRACE_ERROR(msg, mask, args...) TRACE_ERROR(msg, mask, ##args) # define DBG_TRACE_USER(msg, mask, args...) TRACE_USER(msg, mask, ##args) # define DBG_TRACE_DATA(msg, mask, args...) TRACE_DATA(msg, mask, ##args) # define DBG_TRACE_PROTO(msg, mask, args...) TRACE_PROTO(msg, mask, ##args) @@ -89,6 +93,7 @@ # define DBG_TRACE_POINT(mask, args...) TRACE_POINT(mask, ##args) #else # define DBG_TRACE(msg, mask, args...) do { /* do nothing */ } while(0) +# define DBG_TRACE_ERROR(msg, mask, args...) do { /* do nothing */ } while(0) # define DBG_TRACE_USER(msg, mask, args...) do { /* do nothing */ } while(0) # define DBG_TRACE_DATA(msg, mask, args...) do { /* do nothing */ } while(0) # define DBG_TRACE_PROTO(msg, mask, args...) do { /* do nothing */ } while(0) diff --git a/src/trace.c b/src/trace.c index ae35ab45c6..3184354483 100644 --- a/src/trace.c +++ b/src/trace.c @@ -408,7 +408,9 @@ static int cli_parse_trace(char **args, char *payload, struct appctx *appctx, vo if (!*name) { chunk_printf(&trash, "Supported trace levels for source %s:\n", src->name.ptr); - chunk_appendf(&trash, " %c user : information useful to the end user\n", + chunk_appendf(&trash, " %c error : report errors\n", + src->level == TRACE_LEVEL_ERROR ? '*' : ' '); + chunk_appendf(&trash, " %c user : also information useful to the end user\n", src->level == TRACE_LEVEL_USER ? '*' : ' '); chunk_appendf(&trash, " %c proto : also protocol-level updates\n", src->level == TRACE_LEVEL_PROTO ? '*' : ' '); @@ -422,7 +424,9 @@ static int cli_parse_trace(char **args, char *payload, struct appctx *appctx, vo return cli_msg(appctx, LOG_WARNING, trash.area); } - if (strcmp(name, "user") == 0) + if (strcmp(name, "error") == 0) + HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_ERROR); + else if (strcmp(name, "user") == 0) HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_USER); else if (strcmp(name, "proto") == 0) HA_ATOMIC_STORE(&src->level, TRACE_LEVEL_PROTO); -- 2.39.5