@@ -514,49 +514,30 @@ static const char *plugin_log_handle(struct plugin *plugin,
514
514
515
515
call_notifier = (level == LOG_BROKEN || level == LOG_UNUSUAL )? true : false;
516
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
- }
517
+ /* Only bother unescaping and splitting if it has \ */
518
+ if (memchr (plugin -> buffer + msgtok -> start , '\\' , msgtok -> end - msgtok -> start )) {
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_ (tmpctx , log_escaped , log_escaped_len );
522
+ const char * log_msg = json_escape_unescape (tmpctx , esc );
523
+ char * * lines ;
538
524
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. */
525
+ lines = tal_strsplit (tmpctx , log_msg , "\n" , STR_EMPTY_OK );
526
+
527
+ for (size_t i = 0 ; lines [i ]; i ++ ) {
548
528
bool call_notifier2 = call_notifier ;
549
- if (log_msg != last_msg ) {
529
+ /* Call notifier only for the last message to avoid Python errors. */
530
+ if (lines [i + 1 ] != NULL )
550
531
call_notifier2 = false;
551
- }
552
532
/* FIXME: Let plugin specify node_id? */
553
- log_ (plugin -> log , level , NULL , call_notifier2 , "%.* s" , msg_len , log_msg );
533
+ log_ (plugin -> log , level , NULL , call_notifier2 , "%s" , lines [ i ] );
554
534
}
555
- log_msg = msg_end + 1 ;
535
+ } else {
536
+ log_ (plugin -> log , level , NULL , call_notifier , "%.*s" ,
537
+ msgtok -> end - msgtok -> start ,
538
+ plugin -> buffer + msgtok -> start );
556
539
}
557
540
558
- tal_free (ctx );
559
-
560
541
return NULL ;
561
542
}
562
543
0 commit comments