1use arc_writer::ArcWriter;
2use once_cell::sync::Lazy;
3use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
4
5static JSON_LOGS: Lazy<ArcWriter<Vec<u8>>> = Lazy::new(|| ArcWriter::new(Vec::new()));
7
8pub fn init_logging() -> anyhow::Result<()> {
10 let json_writer = JSON_LOGS.clone();
12
13 tracing_subscriber::registry()
14 .with(fmt::layer().compact().with_writer(std::io::stderr))
16 .with(fmt::layer().json().with_writer(move || json_writer.clone()))
18 .with(
20 EnvFilter::builder()
21 .with_default_directive("geph=debug".parse()?)
22 .from_env_lossy(),
23 )
24 .init();
25
26 Ok(())
27}
28
29pub fn get_json_logs() -> String {
31 let logs = JSON_LOGS.lock();
32
33 let log_string = String::from_utf8_lossy(&logs);
35
36 log_string.to_string()
37}