pub struct Logger { /* private fields */ }Expand description
日志记录器结构体
Implementations§
Source§impl Logger
impl Logger
Sourcepub const fn new(module_path: &'static str, log_level: LogLevel) -> Self
pub const fn new(module_path: &'static str, log_level: LogLevel) -> Self
初始化日志记录器实例
- 创建一个新的日志记录器实例,指定模块路径和日志级别。
- 此方法仅创建实例,要启用全局日志系统需要调用
Logger::init方法。 - 可用于设置单独某个模块的日志级别
§参数
module_path: 当前模块的路径标识,用于日志记录中的来源标识log_level: 日志记录器的过滤级别
§返回值
Logger: 初始化完成的日志记录器实例
§示例
let log = yan_log::Logger::new(module_path!(), yan_log::LogLevel::Debug);
log.debug("Debug information");
yan_log::Logger::shutdown();Sourcepub fn init(dir_path: &str, level: LogLevel) -> LoggerFormat
pub fn init(dir_path: &str, level: LogLevel) -> LoggerFormat
初始化全局日志系统
- 搭配 log 日志门面框架使用
- 设置日志发送器和全局日志级别,使日志系统开始工作
- 此方法只需在应用程序启动时调用一次
§参数
dir_path: 日志文件存储目录路径level: 全局日志级别过滤设置
§注意事项
- 必须在创建任何日志记录器实例之前调用
- 如果未调用此方法,日志将无法正常记录
- 设置全局日志级别会影响所有日志记录器
§示例
yan_log::Logger::init("logs", yan_log::LogLevel::Debug)
.start()
.unwrap();
log::info!("Application started");
yan_log::Logger::shutdown();Trait Implementations§
Auto Trait Implementations§
impl Freeze for Logger
impl RefUnwindSafe for Logger
impl Send for Logger
impl Sync for Logger
impl Unpin for Logger
impl UnwindSafe for Logger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more