libplugin: create debug message for notifications

Makes it easier to post-mortem in the logs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-07-01 13:59:01 +09:30
parent 3657f26163
commit 38fafc7d6d

View file

@ -1064,15 +1064,23 @@ void plugin_notify_message(struct command *cmd,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list ap; va_list ap;
struct json_stream *js = plugin_notify_start(cmd, "message"); struct json_stream *js;
const char *msg;
va_start(ap, fmt); va_start(ap, fmt);
msg = tal_vfmt(tmpctx, fmt, ap);
va_end(ap);
/* Also log, debug level */
plugin_log(cmd->plugin, LOG_DBG, "notify msg %s: %s",
log_level_name(level), msg);
js = plugin_notify_start(cmd, "message");
json_add_string(js, "level", log_level_name(level)); json_add_string(js, "level", log_level_name(level));
/* In case we're OOM */ /* In case we're OOM */
if (js->jout) if (js->jout)
json_out_addv(js->jout, "message", true, fmt, ap); json_out_addstr(js->jout, "message", msg);
va_end(ap);
plugin_notify_end(cmd, js); plugin_notify_end(cmd, js);
} }