| 525 | } |
| 526 | |
| 527 | void json_notify_fmt(struct command *cmd, |
| 528 | enum log_level level, |
| 529 | const char *fmt, ...) |
| 530 | { |
| 531 | va_list ap; |
| 532 | struct json_stream *js; |
| 533 | |
| 534 | if (!cmd->send_notifications) |
| 535 | return; |
| 536 | |
| 537 | js = json_stream_raw_for_cmd(cmd); |
| 538 | |
| 539 | va_start(ap, fmt); |
| 540 | json_object_start(js, NULL); |
| 541 | json_add_string(js, "jsonrpc", "2.0"); |
| 542 | json_add_string(js, "method", "message"); |
| 543 | json_object_start(js, "params"); |
| 544 | if (cmd->id_is_string) |
| 545 | json_add_string(js, "id", cmd->id); |
| 546 | else |
| 547 | json_add_jsonstr(js, "id", cmd->id, strlen(cmd->id)); |
| 548 | json_add_string(js, "level", log_level_name(level)); |
| 549 | json_add_string(js, "message", tal_vfmt(tmpctx, fmt, ap)); |
| 550 | json_object_end(js); |
| 551 | json_object_end(js); |
| 552 | |
| 553 | json_stream_double_cr(js); |
| 554 | json_stream_flush(js); |
| 555 | } |
| 556 | |
| 557 | struct json_stream *json_stream_raw_for_cmd(struct command *cmd) |
| 558 | { |
no test coverage detected