mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-01 03:24:41 +01:00
9d4148ce68
We recently noticed that the way we unpack the call arguments for hooks and notifications in pylightning breaks pretty quickly once you start changing the hook and notification params. If you add params they will not get mapped correctly causing the plugin to error out. This can be fixed by adding a `VAR_KEYWORD` argument to the calbacks, i.e., by adding a single `**kwargs` argument at the end of the signature. This commit adds a check that such a catch-all argument exists, and emits a warning if it doesn't. It also fixes up the plugins that we ship ourselves. Signed-off-by: Christian Decker <decker.christian@gmail.com>
33 lines
832 B
Python
Executable File
33 lines
832 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""This plugin is used to check that warning(unusual/broken level log) calls are working correctly.
|
|
"""
|
|
from lightning import Plugin
|
|
|
|
plugin = Plugin()
|
|
|
|
|
|
@plugin.init()
|
|
def init(configuration, options, plugin):
|
|
plugin.log("initialized")
|
|
|
|
|
|
@plugin.subscribe("warning")
|
|
def notify_warning(plugin, warning, **kwargs):
|
|
plugin.log("Received warning")
|
|
plugin.log("level: {}".format(warning['level']))
|
|
plugin.log("time: {}".format(warning['time']))
|
|
plugin.log("source: {}".format(warning['source']))
|
|
plugin.log("log: {}".format(warning['log']))
|
|
|
|
|
|
@plugin.method("pretendbad")
|
|
def pretend_bad(event, level, plugin):
|
|
"""Log an specified level entry.
|
|
And in plugin, we use 'warn'/'error' instead of
|
|
'unusual'/'broken'
|
|
"""
|
|
plugin.log("{}".format(event), level)
|
|
|
|
|
|
plugin.run()
|