2021-02-16 13:34:01 +03:00
|
|
|
use std::sync::{Arc, Mutex};
|
2021-02-10 18:31:34 +03:00
|
|
|
|
2021-02-16 13:34:01 +03:00
|
|
|
use tracing_subscriber::{fmt::MakeWriter, EnvFilter};
|
2021-02-09 17:41:01 +03:00
|
|
|
|
2021-02-16 13:34:01 +03:00
|
|
|
mod machine;
|
|
|
|
|
|
|
|
pub use machine::{
|
|
|
|
CryptoStoreError, Device, DeviceLists, MachineCreationError, OlmMachine, Request, RequestType,
|
|
|
|
Sas,
|
2021-02-09 17:41:01 +03:00
|
|
|
};
|
2021-02-16 13:18:31 +03:00
|
|
|
|
|
|
|
pub trait Logger: Send {
|
|
|
|
fn log(&self, log_line: String);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::io::Write for LoggerWrapper {
|
|
|
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
|
|
|
let data = String::from_utf8_lossy(buf).to_string();
|
|
|
|
self.inner.lock().unwrap().log(data);
|
|
|
|
|
|
|
|
Ok(buf.len())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> std::io::Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MakeWriter for LoggerWrapper {
|
|
|
|
type Writer = LoggerWrapper;
|
|
|
|
|
|
|
|
fn make_writer(&self) -> Self::Writer {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct LoggerWrapper {
|
|
|
|
inner: Arc<Mutex<Box<dyn Logger>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_logger(logger: Box<dyn Logger>) {
|
|
|
|
let logger = LoggerWrapper {
|
|
|
|
inner: Arc::new(Mutex::new(logger)),
|
|
|
|
};
|
|
|
|
|
|
|
|
let filter = EnvFilter::from_default_env().add_directive(
|
|
|
|
"matrix_sdk_crypto=trace"
|
|
|
|
.parse()
|
|
|
|
.expect("Can't parse logging filter directive"),
|
|
|
|
);
|
|
|
|
|
|
|
|
let _ = tracing_subscriber::fmt()
|
|
|
|
.with_writer(logger)
|
|
|
|
.with_env_filter(filter)
|
|
|
|
.without_time()
|
|
|
|
.try_init();
|
|
|
|
}
|
2021-02-09 17:41:01 +03:00
|
|
|
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/olm.uniffi.rs"));
|