From f2628a954c0de88d30750cd130cc4d56971fb924 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 11 Jun 2023 16:48:27 +0200 Subject: [PATCH] feat(util/iobuf): Improve log output Output the full buffer and the buffer up to the currently set position. Makes debugging a lot easier if you know the position set is ok to only look at the output up to there. Otherwise, having the full view is also important to check if data got truncated or checking for odd looking "garbage" data. --- src/main/util/iobuf.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/util/iobuf.c b/src/main/util/iobuf.c index c2d0ad1..45884ea 100644 --- a/src/main/util/iobuf.c +++ b/src/main/util/iobuf.c @@ -14,11 +14,18 @@ void iobuf_log(struct iobuf *buffer, const char *tag) str = xmalloc(str_len); log_misc( - "[%s] (%d %d)", tag, (uint32_t) buffer->nbytes, (uint32_t) buffer->pos); + "[%s] (nbytes %d, pos %d)", + tag, + (uint32_t) buffer->nbytes, + (uint32_t) buffer->pos); hex_encode_uc(buffer->bytes, buffer->nbytes, str, str_len); - log_misc("[%s]: %s", tag, str); + log_misc("full [%s]: %s", tag, str); + + hex_encode_uc(buffer->bytes, buffer->pos, str, str_len); + + log_misc("pos [%s]: %s", tag, str); free(str); } @@ -32,11 +39,18 @@ void iobuf_log_const(struct const_iobuf *buffer, const char *tag) str = xmalloc(str_len); log_misc( - "[%s] (%d %d)", tag, (uint32_t) buffer->nbytes, (uint32_t) buffer->pos); + "[%s] (nbytes %d, pos %d)", + tag, + (uint32_t) buffer->nbytes, + (uint32_t) buffer->pos); hex_encode_uc(buffer->bytes, buffer->nbytes, str, str_len); - log_misc("[%s]: %s", tag, str); + log_misc("full [%s]: %s", tag, str); + + hex_encode_uc(buffer->bytes, buffer->pos, str, str_len); + + log_misc("pos [%s]: %s", tag, str); free(str); }