MCPcopy Create free account
hub / github.com/ElementsProject/lightning / start_writer

Function start_writer

plugins/src/logging.rs:43–64  ·  view source on GitHub ↗

Start a listener that receives incoming log events, and then writes them out to `stdout`, after wrapping them in a valid JSON-RPC notification object.

(out: Arc<Mutex<FramedWrite<O, JsonCodec>>>)

Source from the content-addressed store, hash-verified

41/// writes them out to `stdout`, after wrapping them in a valid
42/// JSON-RPC notification object.
43fn start_writer<O>(out: Arc<Mutex<FramedWrite<O, JsonCodec>>>) -> mpsc::UnboundedSender<LogEntry>
44where
45 O: AsyncWrite + Send + Unpin + 'static,
46{
47 let (sender, mut receiver) = mpsc::unbounded_channel::<LogEntry>();
48 tokio::spawn(async move {
49 while let Some(i) = receiver.recv().await {
50 // We continue draining the queue, even if we get some
51 // errors when forwarding. Forwarding could break due to
52 // an interrupted connection or stdout being closed, but
53 // keeping the messages in the queue is a memory leak.
54 let payload = json!({
55 "jsonrpc": "2.0",
56 "method": "log",
57 "params": i
58 });
59
60 let _ = out.lock().await.send(payload).await;
61 }
62 });
63 sender
64}
65
66/// Initialize the logger starting a flusher to the passed in sink.
67pub async fn init<O>(out: Arc<Mutex<FramedWrite<O, JsonCodec>>>) -> Result<(), anyhow::Error>

Callers 1

initFunction · 0.85

Calls 2

recvMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected