ferroui_splat/logging/
log_manager.rs1use super::IFullLogger;
4use std::rc::Rc;
5
6pub trait ILogManager {
8 fn get_logger(&self, type_name: &'static str) -> Rc<dyn IFullLogger>;
10}
11
12pub trait LogManagerExt: ILogManager {
14 fn get_logger_for<T: ?Sized>(&self) -> Rc<dyn IFullLogger> {
16 self.get_logger(std::any::type_name::<T>())
17 }
18}
19
20impl<M: ILogManager + ?Sized> LogManagerExt for M {}
21
22pub struct FuncLogManager {
24 get_logger_func: Box<dyn Fn(&'static str) -> Rc<dyn IFullLogger>>,
25}
26
27impl FuncLogManager {
28 pub fn new(get_logger_func: impl Fn(&'static str) -> Rc<dyn IFullLogger> + 'static) -> Self {
30 Self { get_logger_func: Box::new(get_logger_func) }
31 }
32}
33
34impl ILogManager for FuncLogManager {
35 fn get_logger(&self, type_name: &'static str) -> Rc<dyn IFullLogger> {
36 (self.get_logger_func)(type_name)
37 }
38}