mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
b7acd93578
We currently don't handle LOG_IO properly, and we turn it into a string before handing it to the ->print function, which makes it ugly for the case where we're using copy_to_parent_log, and also means in that case we lose *what peer* the IO is coming from. Now, we handle the io as a separate arg, which is much neater. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
27 lines
599 B
C
27 lines
599 B
C
#include <lightningd/log_status.h>
|
|
#include <wire/wire.h>
|
|
|
|
bool log_status_msg(struct log *log, const u8 *msg)
|
|
{
|
|
size_t max = tal_len(msg);
|
|
int type = fromwire_u16(&msg, &max);
|
|
enum log_level level;
|
|
|
|
if (type < STATUS_LOG_MIN || type > STATUS_LOG_MAX)
|
|
return false;
|
|
|
|
level = type - STATUS_LOG_MIN;
|
|
if (level == LOG_IO_IN || level == LOG_IO_OUT) {
|
|
log_io(log, level, "", msg, max);
|
|
} else {
|
|
int i;
|
|
/* Truncate if unprintable */
|
|
for (i = 0; i < max; i++) {
|
|
if (!cisprint((char)msg[i]))
|
|
break;
|
|
}
|
|
log_(log, level, "%.*s%s", i, msg, i == max ? "" : "...");
|
|
}
|
|
return true;
|
|
}
|