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.
This commit is contained in:
icex2
2023-06-11 17:36:22 +02:00
parent 178d4afec8
commit b803084cc8
+18 -4
View File
@@ -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);
}