|
3 | 3 | #include <ccan/ccan/tal/grab_file/grab_file.h>
|
4 | 4 | #include <ccan/crc32c/crc32c.h>
|
5 | 5 | #include <ccan/io/io.h>
|
| 6 | +#include <ccan/json_escape/json_escape.h> |
6 | 7 | #include <ccan/mem/mem.h>
|
7 | 8 | #include <ccan/opt/opt.h>
|
8 | 9 | #include <ccan/pipecmd/pipecmd.h>
|
@@ -512,9 +513,50 @@ static const char *plugin_log_handle(struct plugin *plugin,
|
512 | 513 | }
|
513 | 514 |
|
514 | 515 | call_notifier = (level == LOG_BROKEN || level == LOG_UNUSUAL)? true : false;
|
515 |
| - /* FIXME: Let plugin specify node_id? */ |
516 |
| - log_(plugin->log, level, NULL, call_notifier, "%.*s", msgtok->end - msgtok->start, |
517 |
| - plugin->buffer + msgtok->start); |
| 516 | + |
| 517 | + /* Unescape log message. */ |
| 518 | + tal_t *ctx = tal(NULL, char); |
| 519 | + const char *log_escaped = plugin->buffer + msgtok->start; |
| 520 | + const size_t log_escaped_len = msgtok->end - msgtok->start; |
| 521 | + struct json_escape *esc = json_escape_string_(ctx, log_escaped, log_escaped_len); |
| 522 | + const char *log_msg = json_escape_unescape(ctx, esc); |
| 523 | + |
| 524 | + /* Find last line. */ |
| 525 | + const char *log_msg2 = log_msg; |
| 526 | + const char *last_msg; |
| 527 | + while (true) { |
| 528 | + const char *msg_end = strchr(log_msg2, '\n'); |
| 529 | + if (!msg_end) { |
| 530 | + break; |
| 531 | + } |
| 532 | + int msg_len = msg_end - log_msg2; |
| 533 | + if (msg_len > 0) { |
| 534 | + last_msg = log_msg2; |
| 535 | + } |
| 536 | + log_msg2 = msg_end + 1; |
| 537 | + } |
| 538 | + |
| 539 | + /* Split to lines and log them separately. */ |
| 540 | + while (true) { |
| 541 | + const char *msg_end = strchr(log_msg, '\n'); |
| 542 | + if (!msg_end) { |
| 543 | + break; |
| 544 | + } |
| 545 | + int msg_len = msg_end - log_msg; |
| 546 | + if (msg_len > 0) { |
| 547 | + /* Call notifier only for the last message to avoid Python errors. */ |
| 548 | + bool call_notifier2 = call_notifier; |
| 549 | + if (log_msg != last_msg) { |
| 550 | + call_notifier2 = false; |
| 551 | + } |
| 552 | + /* FIXME: Let plugin specify node_id? */ |
| 553 | + log_(plugin->log, level, NULL, call_notifier2, "%.*s", msg_len, log_msg); |
| 554 | + } |
| 555 | + log_msg = msg_end + 1; |
| 556 | + } |
| 557 | + |
| 558 | + tal_free(ctx); |
| 559 | + |
518 | 560 | return NULL;
|
519 | 561 | }
|
520 | 562 |
|
|
0 commit comments