From 29c8611e5343a398a1a0470a9e380cd3ed972c70 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:41:48 +1030 Subject: [PATCH] daemon: add helper to log hex. Good for keys; eventually we'll want to log structures by type though. Signed-off-by: Rusty Russell --- daemon/log.c | 7 +++++++ daemon/log.h | 1 + 2 files changed, 8 insertions(+) diff --git a/daemon/log.c b/daemon/log.c index e48aa46cc..1e69f8133 100644 --- a/daemon/log.c +++ b/daemon/log.c @@ -262,6 +262,13 @@ void log_add(struct log *log, const char *fmt, ...) va_end(ap); } +void log_add_hex(struct log *log, const void *data, size_t len) +{ + char hex[hex_str_size(len)]; + hex_encode(data, len, hex, hex_str_size(len)); + log_add(log, "%s", hex); +} + void log_each_line_(const struct log_record *lr, void (*func)(unsigned int skipped, struct timerel time, diff --git a/daemon/log.h b/daemon/log.h index 45c438ae5..3dcdefcb6 100644 --- a/daemon/log.h +++ b/daemon/log.h @@ -39,6 +39,7 @@ void log_io(struct log *log, bool in, const void *data, size_t len); void log_(struct log *log, enum log_level level, const char *fmt, ...) PRINTF_FMT(3,4); void log_add(struct log *log, const char *fmt, ...) PRINTF_FMT(2,3); +void log_add_hex(struct log *log, const void *data, size_t len); void logv(struct log *log, enum log_level level, const char *fmt, va_list ap); #define log_add_struct(log, structtype, ptr) \