|
7 | 7 | #include <ccan/tal/str/str.h> |
8 | 8 | #include <common/configvar.h> |
9 | 9 | #include <common/json_command.h> |
| 10 | +#include <ccan/json_escape/json_escape.h> |
10 | 11 | #include <common/json_param.h> |
11 | 12 | #include <common/memleak.h> |
12 | 13 | #include <errno.h> |
@@ -570,21 +571,35 @@ void logv(struct logger *log, enum log_level level, |
570 | 571 | if (vasprintf(&l->log, fmt, ap) == -1) |
571 | 572 | abort(); |
572 | 573 |
|
573 | | - size_t log_len = strlen(l->log); |
574 | | - |
575 | | - /* Sanitize any non-printable characters, and replace with '?' */ |
576 | | - for (size_t i=0; i<log_len; i++) |
577 | | - if (l->log[i] < ' ' || l->log[i] >= 0x7f) |
578 | | - l->log[i] = '?'; |
579 | | - |
580 | | - maybe_print(log, l); |
581 | | - maybe_notify_log(log, l); |
582 | | - |
583 | | - add_entry(log, &l); |
| 574 | + tal_t *ctx = tal(NULL, char); |
| 575 | + const char *log_line = tal_strdup( |
| 576 | + ctx, json_escape_unescape(ctx, (struct json_escape *)l->log)); |
| 577 | + char **lines = tal_strsplit(ctx, log_line, "\n", STR_NO_EMPTY); |
| 578 | + |
| 579 | + /* Split to lines and log them separately. */ |
| 580 | + for (size_t i = 0; i < tal_count(lines) - 1; i++) { |
| 581 | + struct log_entry *line_entry = |
| 582 | + new_log_entry(log, level, node_id); |
| 583 | + line_entry->log = tal_strdup(ctx, lines[i]); |
| 584 | + |
| 585 | + /* Sanitize any non-printable characters, and replace with '?' |
| 586 | + */ |
| 587 | + size_t line_len = strlen(line_entry->log); |
| 588 | + for (size_t i = 0; i < line_len; i++) |
| 589 | + if (line_entry->log[i] < ' ' || |
| 590 | + line_entry->log[i] >= 0x7f) |
| 591 | + line_entry->log[i] = '?'; |
| 592 | + |
| 593 | + maybe_print(log, line_entry); |
| 594 | + maybe_notify_log(log, line_entry); |
| 595 | + |
| 596 | + add_entry(log, &line_entry); |
| 597 | + } |
584 | 598 |
|
585 | 599 | if (call_notifier) |
586 | 600 | notify_warning(log->log_book->ld, l); |
587 | 601 |
|
| 602 | + tal_free(ctx); |
588 | 603 | errno = save_errno; |
589 | 604 | } |
590 | 605 |
|
|
0 commit comments