pub struct LogRotator { /* private fields */ }Expand description
日志轮转器(内存模拟)。
维护一个当前日志缓冲与一组已轮转的历史日志。当当前缓冲满足轮转策略时,
将其移入历史列表并开启新的空缓冲。历史列表长度不超过 max_files,
超出时丢弃最旧的。
实际生产环境中,轮转器会将缓冲刷盘到文件(如 app.log -> app.log.1),
此处用内存 Vec<u8> 模拟以便测试。
Implementations§
Source§impl LogRotator
impl LogRotator
Sourcepub fn new(policy: RotationPolicy, max_files: usize) -> Self
pub fn new(policy: RotationPolicy, max_files: usize) -> Self
Sourcepub fn current_size(&self) -> usize
pub fn current_size(&self) -> usize
获取当前缓冲的字节大小
Sourcepub fn rotated_count(&self) -> usize
pub fn rotated_count(&self) -> usize
获取已轮转的历史日志数量
Sourcepub fn total_rotations(&self) -> u64
pub fn total_rotations(&self) -> u64
获取总轮转次数(含因 max_files 限制被丢弃的)
Sourcepub fn current_content(&self) -> Vec<u8> ⓘ
pub fn current_content(&self) -> Vec<u8> ⓘ
获取当前缓冲内容的快照(拷贝)
Sourcepub fn current_age(&self) -> Duration
pub fn current_age(&self) -> Duration
获取当前缓冲已存活的时长
Sourcepub fn policy(&self) -> &RotationPolicy
pub fn policy(&self) -> &RotationPolicy
获取轮转策略引用
Auto Trait Implementations§
impl !Freeze for LogRotator
impl !RefUnwindSafe for LogRotator
impl Send for LogRotator
impl Sync for LogRotator
impl Unpin for LogRotator
impl UnsafeUnpin for LogRotator
impl UnwindSafe for LogRotator
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