Skip to content

Commit

Permalink
logv: replace "\n" with line break in the log
Browse files Browse the repository at this point in the history
Fix #4912
  • Loading branch information
starius committed Jan 25, 2024
1 parent d9a747e commit b462dde
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lightningd/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,19 @@ void logv(struct logger *log, enum log_level level,
if (l->log[i] < ' ' || l->log[i] >= 0x7f)
l->log[i] = '?';

/* Replace "\n" with line breaks in the log, if they exist. */
char *write_ptr = l->log;
for (size_t i=0; i<log_len; i++) {
if (l->log[i] == '\\' && i < log_len-1 && l->log[i+1] == 'n') {
*write_ptr = '\n';
i++;
} else {
*write_ptr = l->log[i];
}
write_ptr++;
}
*write_ptr = 0x00;

maybe_print(log, l);

add_entry(log, &l);
Expand Down

0 comments on commit b462dde

Please sign in to comment.