summaryrefslogtreecommitdiffstats
path: root/lib/zlog.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2021-03-22 13:45:20 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2021-06-18 20:56:53 +0200
commite3daa82c1897c289384988add6932f74b0de4e9e (patch)
tree3ee16ff1e19c039e82360a353e11aa753c8c7d23 /lib/zlog.c
parentlib: add hook for `show logging` CLI (diff)
downloadfrr-e3daa82c1897c289384988add6932f74b0de4e9e.tar.xz
frr-e3daa82c1897c289384988add6932f74b0de4e9e.zip
lib: record output argument positions in zlog
printfrr() recently acquired the capability to record start/end of formatting outputs. Make use of this in the zlog code so logging targets have access to this information. (This also records how long the `[XXXXX-XXXXX][EC 9999999]` prefix was so log targets can choose to skip over it.) Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/zlog.c')
-rw-r--r--lib/zlog.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/zlog.c b/lib/zlog.c
index 89ab9265d..c96e2fc08 100644
--- a/lib/zlog.c
+++ b/lib/zlog.c
@@ -107,6 +107,7 @@ struct zlog_msg {
size_t stackbufsz;
char *text;
size_t textlen;
+ size_t hdrlen;
/* This is always ISO8601 with sub-second precision 9 here, it's
* converted for callers as needed. ts_dot points to the "."
@@ -118,6 +119,15 @@ struct zlog_msg {
*/
uint32_t ts_flags;
char ts_str[32], *ts_dot, ts_zonetail[8];
+
+ /* at the time of writing, 16 args was the actual maximum of arguments
+ * to a single zlog call. Particularly printing flag bitmasks seems
+ * to drive this. That said, the overhead of dynamically sizing this
+ * probably outweighs the value. If anything, a printfrr extension
+ * for printing flag bitmasks might be a good idea.
+ */
+ struct fmt_outpos argpos[24];
+ size_t n_argpos;
};
/* thread-local log message buffering
@@ -592,9 +602,13 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
if (need)
need += bputch(&fb, ' ');
- hdrlen = need;
+ msg->hdrlen = hdrlen = need;
assert(hdrlen < msg->stackbufsz);
+ fb.outpos = msg->argpos;
+ fb.outpos_n = array_size(msg->argpos);
+ fb.outpos_i = 0;
+
va_copy(args, msg->args);
need += vbprintfrr(&fb, msg->fmt, args);
va_end(args);
@@ -612,6 +626,7 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
fb.buf = msg->text;
fb.len = need;
fb.pos = msg->text + hdrlen;
+ fb.outpos_i = 0;
va_copy(args, msg->args);
vbprintfrr(&fb, msg->fmt, args);
@@ -619,12 +634,28 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
bputch(&fb, '\0');
}
+
+ msg->n_argpos = fb.outpos_i;
}
if (textlen)
*textlen = msg->textlen;
return msg->text;
}
+void zlog_msg_args(struct zlog_msg *msg, size_t *hdrlen, size_t *n_argpos,
+ const struct fmt_outpos **argpos)
+{
+ if (!msg->text)
+ zlog_msg_text(msg, NULL);
+
+ if (hdrlen)
+ *hdrlen = msg->hdrlen;
+ if (n_argpos)
+ *n_argpos = msg->n_argpos;
+ if (argpos)
+ *argpos = msg->argpos;
+}
+
#define ZLOG_TS_FORMAT (ZLOG_TS_ISO8601 | ZLOG_TS_LEGACY)
#define ZLOG_TS_FLAGS ~ZLOG_TS_PREC