06_log_crate/
06-log-crate.rs1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 spdlog::init_log_crate_proxy()
3 .expect("users should only call `init_log_crate_proxy` function once");
4
5 let filter = env_filter::Builder::new().try_parse("RUST_LOG")?.build();
7 spdlog::log_crate_proxy().set_filter(Some(filter));
8
9 log::set_max_level(log::LevelFilter::Trace);
10 log::trace!("this log will be processed by the global default logger in spdlog-rs");
11
12 let custom_logger = spdlog::default_logger().fork_with_name(Some("another_logger"))?;
13 spdlog::log_crate_proxy().set_logger(Some(custom_logger));
14 log::info!("this log will be processed by custom_logger in spdlog-rs");
15
16 spdlog::log_crate_proxy().set_logger(None);
17 log::trace!("this log will be processed by the global default logger in spdlog-rs");
18
19 Ok(())
20}