Skip to content

Commit 459c756

Browse files
daywalker90ShahanaFarooqui
authored andcommitted
cln-plugin: trace level logging support
Changelog-None
1 parent f8ca160 commit 459c756

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

plugins/examples/cln-plugin-startup.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ async fn main() -> Result<(), anyhow::Error> {
7676
"send a test_custom_notification event",
7777
test_send_custom_notification,
7878
)
79+
.rpcmethod("test-log-levels", "send on all log levels", test_log_levels)
7980
.subscribe("connect", connect_handler)
8081
.subscribe("test_custom_notification", test_receive_custom_notification)
8182
.hook("peer_connected", peer_connected_handler)
@@ -161,3 +162,15 @@ async fn peer_connected_handler(
161162
log::info!("Got a connect hook call: {}", v);
162163
Ok(json!({"result": "continue"}))
163164
}
165+
166+
async fn test_log_levels(
167+
_p: Plugin<()>,
168+
_v: serde_json::Value,
169+
) -> Result<serde_json::Value, Error> {
170+
log::trace!("log::trace! working");
171+
log::debug!("log::debug! working");
172+
log::info!("log::info! working");
173+
log::warn!("log::warn! working");
174+
log::error!("log::error! working");
175+
Ok(json!({}))
176+
}

plugins/src/logging.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum LogLevel {
2222
Info,
2323
Warn,
2424
Error,
25+
Trace,
2526
}
2627

2728
impl From<log::Level> for LogLevel {
@@ -30,7 +31,8 @@ impl From<log::Level> for LogLevel {
3031
log::Level::Error => LogLevel::Error,
3132
log::Level::Warn => LogLevel::Warn,
3233
log::Level::Info => LogLevel::Info,
33-
log::Level::Debug | log::Level::Trace => LogLevel::Debug,
34+
log::Level::Debug => LogLevel::Debug,
35+
log::Level::Trace => LogLevel::Trace,
3436
}
3537
}
3638
}
@@ -130,7 +132,7 @@ mod trace {
130132
&Level::ERROR => LogLevel::Error,
131133
&Level::INFO => LogLevel::Info,
132134
&Level::WARN => LogLevel::Warn,
133-
&Level::TRACE => LogLevel::Debug,
135+
&Level::TRACE => LogLevel::Trace,
134136
}
135137
}
136138
}

tests/test_cln_rs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ def test_plugin_options_handle_defaults(node_factory):
105105
assert opts["multi-i64-option-default"] == [-42]
106106

107107

108+
def test_plugin_log_levels(node_factory):
109+
"""Start a minimal plugin and ensure it logs all levels"""
110+
bin_path = Path.cwd() / "target" / RUST_PROFILE / "examples" / "cln-plugin-startup"
111+
l1 = node_factory.get_node(
112+
options={"plugin": str(bin_path)}, broken_log=r"log::error! working"
113+
)
114+
l1.rpc.test_log_levels()
115+
wait_for(lambda: l1.daemon.is_in_log(r"cln-plugin-startup: log::trace! working"))
116+
wait_for(lambda: l1.daemon.is_in_log(r"cln-plugin-startup: log::debug! working"))
117+
wait_for(lambda: l1.daemon.is_in_log(r"cln-plugin-startup: log::info! working"))
118+
wait_for(lambda: l1.daemon.is_in_log(r"cln-plugin-startup: log::warn! working"))
119+
wait_for(lambda: l1.daemon.is_in_log(r"cln-plugin-startup: log::error! working"))
120+
121+
108122
def test_grpc_connect(node_factory):
109123
"""Attempts to connect to the grpc interface and call getinfo"""
110124
# These only exist if we have rust!

0 commit comments

Comments
 (0)