Skip to content

Commit 0c3008d

Browse files
reckless-rpc: publish reckless log notifications
Changelog-added: The reckless-rpc plugin streams logs via the notification topic 'reckless_log'
1 parent f947d79 commit 0c3008d

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

plugins/recklessrpc.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ static bool is_single_arg_cmd(const char *command) {
241241
return false;
242242
}
243243

244+
static void log_notify(char * log_line TAKES)
245+
{
246+
struct json_stream *js = plugin_notification_start(NULL, "reckless_log");
247+
json_add_stringn(js, "log", log_line, tal_count(log_line));
248+
plugin_notification_end(plugin, js);
249+
}
250+
244251
static void log_conn_finish(struct io_conn *conn, struct reckless *reckless)
245252
{
246253
io_close(conn);
@@ -263,8 +270,8 @@ static struct io_plan *log_read_more(struct io_conn *conn,
263270
char * note;
264271
note = tal_strndup(tmpctx, rkls->log_to_process,
265272
lineend - rkls->log_to_process);
266-
/* FIXME: Add notification for the utility logs. */
267-
plugin_log(plugin, LOG_DBG, "RECKLESS UTILITY: %s", note);
273+
plugin_log(plugin, LOG_DBG, "reckless utility: %s", note);
274+
log_notify(note);
268275
rkls->log_to_process = lineend + 1;
269276
unprocessed = rkls->log_read - (rkls->log_to_process - rkls->logbuf);
270277
lineend = memchr(rkls->log_to_process, 0x0A, unprocessed);
@@ -444,6 +451,10 @@ static const struct plugin_command commands[] = {
444451
},
445452
};
446453

454+
static const char *notifications[] = {
455+
"reckless_log",
456+
};
457+
447458
int main(int argc, char **argv)
448459
{
449460
setup_locale();
@@ -453,7 +464,7 @@ int main(int argc, char **argv)
453464
commands, ARRAY_SIZE(commands),
454465
NULL, 0, /* Notifications */
455466
NULL, 0, /* Hooks */
456-
NULL, 0, /* Notification topics */
467+
notifications, ARRAY_SIZE(notifications), /* Notification topics */
457468
NULL); /* plugin options */
458469

459470
return 0;

tests/plugins/custom_notifications.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,10 @@ def on_faulty_emit(origin, payload, **kwargs):
5151
plugin.log("Got the ididntannouncethis event")
5252

5353

54+
@plugin.subscribe("reckless_log")
55+
def on_reckless_log(origin, **kwargs):
56+
plugin.log("Got reckless_log: {}".format(kwargs))
57+
58+
5459
plugin.add_notification_topic("custom")
5560
plugin.run()

tests/test_reckless.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ def reckless(cmds: list, dir: PosixPath = None,
140140
return RecklessResult(r, r.returncode, stdout, stderr)
141141

142142

143-
def get_reckless_node(node_factory):
143+
def get_reckless_node(node_factory, options={}, start=False):
144144
'''This may be unnecessary, but a preconfigured lightning dir
145145
is useful for reckless testing.'''
146-
node = node_factory.get_node(options={}, start=False)
146+
node = node_factory.get_node(options=options, start=start)
147147
return node
148148

149149

@@ -461,3 +461,16 @@ def test_reckless_available(node_factory):
461461
assert r.search_stdout('testplugpass')
462462
assert r.search_stdout('testplugpyproj')
463463
assert r.search_stdout('testpluguv')
464+
465+
466+
def test_reckless_notifications(node_factory):
467+
"""Reckless streams logs to the reckless-rpc plugin which are emitted
468+
as 'reckless_log' notifications"""
469+
notification_plugin = os.path.join(os.getcwd(), 'tests/plugins/custom_notifications.py')
470+
node = get_reckless_node(node_factory, options={"plugin": notification_plugin})
471+
node.start()
472+
listconfig_log = node.rpc.reckless('listconfig')['log']
473+
# Some trouble escaping the clone url for searching
474+
listconfig_log.pop(1)
475+
for log in listconfig_log:
476+
assert node.daemon.is_in_log(f"reckless_log: {{'reckless_log': {{'log': '{log}'", start=0)

0 commit comments

Comments
 (0)