diff --git a/lightningd/json_stream.c b/lightningd/json_stream.c index 9f6594e2c..a90b98b58 100644 --- a/lightningd/json_stream.c +++ b/lightningd/json_stream.c @@ -65,7 +65,9 @@ struct json_stream *new_json_stream(const tal_t *ctx, return js; } -struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *original) +struct json_stream *json_stream_dup(const tal_t *ctx, + struct json_stream *original, + struct log *log) { size_t num_elems = membuf_num_elems(&original->outbuf); char *elems = membuf_elems(&original->outbuf); @@ -83,6 +85,7 @@ struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *origin membuf_added(&js->outbuf, num_elems); } } + js->log = log; return js; } diff --git a/lightningd/json_stream.h b/lightningd/json_stream.h index 34b2e27ec..bca4b3521 100644 --- a/lightningd/json_stream.h +++ b/lightningd/json_stream.h @@ -36,8 +36,11 @@ struct json_stream *new_json_stream(const tal_t *ctx, struct command *writer, * * @ctx: tal context for allocation. * @original: the stream to duplicate. + * @log: log for new stream. */ -struct json_stream *json_stream_dup(const tal_t *ctx, struct json_stream *original); +struct json_stream *json_stream_dup(const tal_t *ctx, + struct json_stream *original, + struct log *log); /** * json_stream_close - finished writing to a JSON stream. diff --git a/lightningd/plugin.c b/lightningd/plugin.c index b4c8c2cee..11326b486 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -374,6 +374,10 @@ static struct io_plan *plugin_read_json(struct io_conn *conn UNUSED, struct plugin *plugin) { bool success; + + log_io(plugin->log, LOG_IO_IN, "", + plugin->buffer + plugin->used, plugin->len_read); + plugin->used += plugin->len_read; if (plugin->used == tal_count(plugin->buffer)) tal_resize(&plugin->buffer, plugin->used * 2); @@ -1051,7 +1055,7 @@ void plugins_notify(struct plugins *plugins, struct plugin *p; list_for_each(&plugins->plugins, p, list) { if (plugin_subscriptions_contains(p, n->method)) - plugin_send(p, json_stream_dup(p, n->stream)); + plugin_send(p, json_stream_dup(p, n->stream, p->log)); } if (taken(n)) tal_free(n); @@ -1086,3 +1090,8 @@ void *plugin_exclusive_loop(struct plugin *plugin) return ret; } + +struct log *plugin_get_log(struct plugin *plugin) +{ + return plugin->log; +} diff --git a/lightningd/plugin.h b/lightningd/plugin.h index bb9643bb7..dc0c9e107 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -119,4 +119,10 @@ void plugin_request_send(struct plugin *plugin, */ char *plugin_opt_set(const char *arg, struct plugin_opt *popt); + +/** + * Needed for I/O logging for plugin messages. +*/ +struct log *plugin_get_log(struct plugin *plugin); + #endif /* LIGHTNING_LIGHTNINGD_PLUGIN_H */ diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index 29f48a6a3..132ae3b91 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -74,8 +74,8 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, * currently have a list to store these. We might want * to eventually to inspect in-flight requests. */ ph_req = notleak(tal(hook->plugin, struct plugin_hook_request)); - /* FIXME: do IO logging for these! */ - req = jsonrpc_request_start(NULL, hook->name, NULL, + req = jsonrpc_request_start(NULL, hook->name, + plugin_get_log(hook->plugin), plugin_hook_callback, ph_req); ph_req->hook = hook; ph_req->cb_arg = cb_arg;