Skip to content

Commit 86b160a

Browse files
debug-log-pr
Signed-off-by: Nishant Bansal <[email protected]>
1 parent 7be96ae commit 86b160a

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

lightningd/log.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ccan/tal/str/str.h>
88
#include <common/configvar.h>
99
#include <common/json_command.h>
10+
#include <ccan/json_escape/json_escape.h>
1011
#include <common/json_param.h>
1112
#include <common/memleak.h>
1213
#include <errno.h>
@@ -570,21 +571,35 @@ void logv(struct logger *log, enum log_level level,
570571
if (vasprintf(&l->log, fmt, ap) == -1)
571572
abort();
572573

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+
}
584598

585599
if (call_notifier)
586600
notify_warning(log->log_book->ld, l);
587601

602+
tal_free(ctx);
588603
errno = save_errno;
589604
}
590605

0 commit comments

Comments
 (0)