mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 06:46:35 +03:00
Introduce a flag debug_logging on the core
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
//! # Key-value configuration management.
|
//! # Key-value configuration management.
|
||||||
|
|
||||||
|
use std::sync::atomic;
|
||||||
|
|
||||||
use anyhow::{ensure, Context as _, Result};
|
use anyhow::{ensure, Context as _, Result};
|
||||||
|
|
||||||
use strum::{EnumProperty, IntoEnumIterator};
|
use strum::{EnumProperty, IntoEnumIterator};
|
||||||
@@ -334,6 +336,8 @@ impl Context {
|
|||||||
{
|
{
|
||||||
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
|
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
|
||||||
}
|
}
|
||||||
|
self.sql.set_raw_config(key, value).await?;
|
||||||
|
self.debug_logging.store(0, atomic::Ordering::Release);
|
||||||
} else {
|
} else {
|
||||||
let data: &[u8] = include_bytes!("../assets/webxdc_logging.xdc");
|
let data: &[u8] = include_bytes!("../assets/webxdc_logging.xdc");
|
||||||
|
|
||||||
@@ -347,6 +351,8 @@ impl Context {
|
|||||||
self.sql
|
self.sql
|
||||||
.set_raw_config(key, Some(&msg_id.to_u32().to_string()))
|
.set_raw_config(key, Some(&msg_id.to_u32().to_string()))
|
||||||
.await?;
|
.await?;
|
||||||
|
self.debug_logging
|
||||||
|
.store(msg_id.to_u32(), atomic::Ordering::Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::ops::Deref;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant, SystemTime};
|
use std::time::{Duration, Instant, SystemTime};
|
||||||
|
use std::sync::atomic::{self, AtomicU32};
|
||||||
|
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
use async_channel::{self as channel, Receiver, Sender};
|
use async_channel::{self as channel, Receiver, Sender};
|
||||||
@@ -231,7 +232,9 @@ pub struct InnerContext {
|
|||||||
/// The text of the last error logged and emitted as an event.
|
/// The text of the last error logged and emitted as an event.
|
||||||
/// If the ui wants to display an error after a failure,
|
/// If the ui wants to display an error after a failure,
|
||||||
/// `last_error` should be used to avoid races with the event thread.
|
/// `last_error` should be used to avoid races with the event thread.
|
||||||
pub(crate) last_error: std::sync::RwLock<String>,
|
pub(crate) last_error: RwLock<String>,
|
||||||
|
|
||||||
|
pub(crate) debug_logging: AtomicU32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The state of ongoing process.
|
/// The state of ongoing process.
|
||||||
@@ -361,7 +364,8 @@ impl Context {
|
|||||||
server_id: RwLock::new(None),
|
server_id: RwLock::new(None),
|
||||||
creation_time: std::time::SystemTime::now(),
|
creation_time: std::time::SystemTime::now(),
|
||||||
last_full_folder_scan: Mutex::new(None),
|
last_full_folder_scan: Mutex::new(None),
|
||||||
last_error: std::sync::RwLock::new("".to_string()),
|
last_error: RwLock::new("".to_string()),
|
||||||
|
debug_logging: AtomicU32::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ctx = Context {
|
let ctx = Context {
|
||||||
@@ -437,47 +441,44 @@ impl Context {
|
|||||||
id: self.id,
|
id: self.id,
|
||||||
typ: event.clone(),
|
typ: event.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let context = self.clone();
|
let context = self.clone();
|
||||||
async_std::task::spawn(async move {
|
let debug_logging = context.debug_logging.load(atomic::Ordering::Acquire);
|
||||||
// TODO synchronously is prob. better
|
if debug_logging > 0 {
|
||||||
match context.get_config_int(Config::DebugLogging).await {
|
let time = SystemTime::now()
|
||||||
Err(_) => {} // Probably the database is simply closed (i.e. encrypted and no passphrase available yet)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
Ok(0) => {}
|
.unwrap_or_default()
|
||||||
Ok(debug_logging_webxdc) => {
|
.as_millis() as i64;
|
||||||
let time = SystemTime::now()
|
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_millis() as i64;
|
|
||||||
|
|
||||||
let webxdc_instance_id = MsgId::new(debug_logging_webxdc as u32);
|
async_std::task::block_on(async move {
|
||||||
|
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
||||||
|
|
||||||
match context
|
match context
|
||||||
.internal_write_status_update(
|
.internal_write_status_update(
|
||||||
&webxdc_instance_id,
|
&webxdc_instance_id,
|
||||||
StatusUpdateItem {
|
StatusUpdateItem {
|
||||||
payload: event.to_json(Some(time)),
|
payload: event.to_json(Some(time)),
|
||||||
info: None,
|
info: None,
|
||||||
summary: None,
|
summary: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Can't log event to webxdc status update: {:#}", err);
|
||||||
|
}
|
||||||
|
Ok(serial) => {
|
||||||
|
context.events.emit(Event {
|
||||||
|
id: context.id,
|
||||||
|
typ: EventType::WebxdcStatusUpdate {
|
||||||
|
msg_id: webxdc_instance_id,
|
||||||
|
status_update_serial: serial,
|
||||||
},
|
},
|
||||||
)
|
});
|
||||||
.await
|
|
||||||
{
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Can't log event to webxdc status update: {:#}", err);
|
|
||||||
}
|
|
||||||
Ok(serial) => {
|
|
||||||
context.events.emit(Event {
|
|
||||||
id: context.id,
|
|
||||||
typ: EventType::WebxdcStatusUpdate {
|
|
||||||
msg_id: webxdc_instance_id,
|
|
||||||
status_update_serial: serial,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emits a generic MsgsChanged event (without chat or message id)
|
/// Emits a generic MsgsChanged event (without chat or message id)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::atomic;
|
||||||
|
|
||||||
use anyhow::{ensure, format_err, Context as _, Result};
|
use anyhow::{ensure, format_err, Context as _, Result};
|
||||||
use deltachat_derive::{FromSql, ToSql};
|
use deltachat_derive::{FromSql, ToSql};
|
||||||
@@ -1287,6 +1288,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
|
|||||||
.sql
|
.sql
|
||||||
.set_raw_config(Config::DebugLogging, Some("0"))
|
.set_raw_config(Config::DebugLogging, Some("0"))
|
||||||
.await?;
|
.await?;
|
||||||
|
context.debug_logging.store(0, atomic::Ordering::Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::collections::{HashMap, HashSet};
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::atomic;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{bail, Context as _, Result};
|
use anyhow::{bail, Context as _, Result};
|
||||||
@@ -341,6 +342,12 @@ impl Sql {
|
|||||||
} else {
|
} else {
|
||||||
info!(context, "Opened database {:?}.", self.dbfile);
|
info!(context, "Opened database {:?}.", self.dbfile);
|
||||||
*self.is_encrypted.write().await = Some(passphrase_nonempty);
|
*self.is_encrypted.write().await = Some(passphrase_nonempty);
|
||||||
|
|
||||||
|
let debug_logging = self.get_raw_config_u32(Config::DebugLogging).await?;
|
||||||
|
context
|
||||||
|
.debug_logging
|
||||||
|
.store(debug_logging.unwrap_or(0), atomic::Ordering::Release);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user