]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: traces: add a new level "error" below the "user" level
authorWilly Tarreau <w@1wt.eu>
Tue, 1 Dec 2020 08:46:46 +0000 (09:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 1 Dec 2020 09:25:20 +0000 (10:25 +0100)
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
include/haproxy/trace.h
src/trace.c

index 8bc7d0070c04dbc2450cee8adb289afe94f494ea..953a0b99581881830c86922bafe334506a296d99 100644 (file)
@@ -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
index f200ef1143c336fba53b7e90a53cc376a252346f..25f0831a6b161d1b49fff1d86a8bf5c8752e1b34 100644 (file)
@@ -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)
index ae35ab45c6d665b459a49176167dbe80bbef6de3..31843544838a7e8031f2da997730cb690a35d47f 100644 (file)
@@ -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);