MCPcopy Create free account
hub / github.com/chatmail/core / set_debug_logging_xdc

Function set_debug_logging_xdc

src/debug_logging.rs:131–174  ·  view source on GitHub ↗

Set the webxdc contained in the msg as the current logging xdc on the context and save it to db If id is a `None` value, disable debug logging

(ctx: &Context, id: Option<MsgId>)

Source from the content-addressed store, hash-verified

129/// Set the webxdc contained in the msg as the current logging xdc on the context and save it to db
130/// If id is a `None` value, disable debug logging
131pub(crate) async fn set_debug_logging_xdc(ctx: &Context, id: Option<MsgId>) -> anyhow::Result<()> {
132 match id {
133 Some(msg_id) => {
134 ctx.sql
135 .set_raw_config(
136 Config::DebugLogging.as_ref(),
137 Some(msg_id.to_string().as_ref()),
138 )
139 .await?;
140 {
141 let debug_logging = &mut *ctx.debug_logging.write().expect("RwLock is poisoned");
142 match debug_logging {
143 // Switch logging xdc
144 Some(debug_logging) => debug_logging.msg_id = msg_id,
145 // Bootstrap background loop for message forwarding
146 None => {
147 let (sender, debug_logging_recv) = channel::bounded(1000);
148 let loop_handle = {
149 let ctx = ctx.clone();
150 task::spawn(async move {
151 debug_logging_loop(&ctx, debug_logging_recv).await
152 })
153 };
154 *debug_logging = Some(DebugLogging {
155 msg_id,
156 loop_handle,
157 sender,
158 });
159 }
160 }
161 }
162 info!(ctx, "replacing logging webxdc");
163 }
164 // Delete current debug logging
165 None => {
166 ctx.sql
167 .set_raw_config(Config::DebugLogging.as_ref(), None)
168 .await?;
169 *ctx.debug_logging.write().expect("RwLock is poisoned") = None;
170 info!(ctx, "removing logging webxdc");
171 }
172 }
173 Ok(())
174}

Callers 3

openMethod · 0.85
delete_msg_locallyFunction · 0.85

Calls 5

spawnFunction · 0.85
debug_logging_loopFunction · 0.85
set_raw_configMethod · 0.80
cloneMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected