log: add easy way to log hex blobs.

Use it in one case, and also fix another logging FIXME.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2016-08-31 16:06:32 +09:30
parent 87af51a422
commit bb0bf2b5ad
4 changed files with 42 additions and 4 deletions

View File

@@ -359,6 +359,26 @@ void log_struct_(struct log *log, int level,
tal_free(ctx);
}
void log_blob_(struct log *log, enum log_level level, const char *fmt,
size_t len, ...)
{
va_list ap;
const void *blob;
const char *hex;
/* Macro wrappers ensure we only have one arg. */
va_start(ap, len);
blob = va_arg(ap, void *);
va_end(ap);
hex = tal_hexstr(log, blob, len);
if (level == -1)
log_add(log, fmt, hex);
else
log_(log, level, fmt, hex);
tal_free(hex);
}
void log_each_line_(const struct log_record *lr,
void (*func)(unsigned int skipped,
struct timerel time,