You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use log::*;use std::io::Write;use flexi_logger::writers::{FileLogWriter,LogWriter};use flexi_logger::{Age,Cleanup,Criterion,DeferredNow,FileSpec,Logger,Naming};pubfnfile_logger() -> Box<dynLogWriter>{Box::new(FileLogWriter::builder(FileSpec::default().suppress_timestamp().directory("./logs").discriminant("1").basename("ffplayout"),).append().format(file_formatter).rotate(Criterion::Age(Age::Day),Naming::TimestampsCustomFormat{current_infix:Some(""),format:"%Y-%m-%d",},Cleanup::KeepLogFiles(4),).print_message().try_build().unwrap(),)}fnfile_formatter(w:&mutdynWrite,now:&mutDeferredNow,record:&Record,) -> std::io::Result<()>{write!(
w,"[{}] [{:>5}] {}",
now.now().format("%Y-%m-%d %H:%M:%S%.6f"),
record.level(),
record.args())}fnmain(){Logger::try_with_str("WARN").expect("LogSpecification String has errors").print_message().log_to_stderr().add_writer("Alert",file_logger()).start().unwrap();error!(target :"{Alert,_Default}","This is error message");warn!(target :"{Alert,_Default}","This is a warning");info!(target :"{Alert,_Default}","This is an info message");debug!(target :"{Alert,_Default}","This is an debug message");trace!(target :"{Alert,_Default}","This is an trace message");}
Is there something wrong in my code, or is this a bug?
The text was updated successfully, but these errors were encountered:
jb-alvarado
changed the title
File rotate doesn't delete old logs.
File rotate doesn't delete old logs
Oct 27, 2024
Hi, your code is fine (except that you should keep the LoggerHandle alive (let _logger = Logger::try_with_...). flexi_logger had indeed an issue that is now resolved with 0.29.5. I added also some docu lines at Naming::TimestampsCustomFormat to raise awareness that this variant has its risks (which you avoided).
Hello,
in this code log files get not deleted:
Is there something wrong in my code, or is this a bug?
The text was updated successfully, but these errors were encountered: