2024-05-29 09:02:10 -04:00
|
|
|
use log::*;
|
|
|
|
use std::io::Write;
|
|
|
|
|
|
|
|
use flexi_logger::writers::{FileLogWriter, LogWriter};
|
|
|
|
use flexi_logger::{Age, Cleanup, Criterion, DeferredNow, FileSpec, Logger, Naming};
|
|
|
|
|
2024-10-27 12:23:21 -04:00
|
|
|
pub fn file_logger() -> Box<dyn LogWriter> {
|
|
|
|
Box::new(
|
|
|
|
FileLogWriter::builder(
|
|
|
|
FileSpec::default()
|
|
|
|
.suppress_timestamp()
|
|
|
|
.directory("./logs")
|
|
|
|
.discriminant("1")
|
|
|
|
.basename("ffplayout"),
|
2024-05-29 09:02:10 -04:00
|
|
|
)
|
2024-10-27 12:23:21 -04:00
|
|
|
.append()
|
|
|
|
.format(file_formatter)
|
|
|
|
.rotate(
|
|
|
|
Criterion::Age(Age::Day),
|
|
|
|
Naming::TimestampsCustomFormat {
|
|
|
|
current_infix: Some(""),
|
|
|
|
format: "%Y-%m-%d",
|
|
|
|
},
|
|
|
|
Cleanup::KeepLogFiles(4),
|
2024-05-29 09:02:10 -04:00
|
|
|
)
|
2024-10-27 12:23:21 -04:00
|
|
|
.print_message()
|
|
|
|
.try_build()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
2024-05-29 09:02:10 -04:00
|
|
|
}
|
|
|
|
|
2024-10-27 12:23:21 -04:00
|
|
|
fn file_formatter(
|
2024-05-29 09:02:10 -04:00
|
|
|
w: &mut dyn Write,
|
|
|
|
now: &mut DeferredNow,
|
|
|
|
record: &Record,
|
|
|
|
) -> std::io::Result<()> {
|
|
|
|
write!(
|
|
|
|
w,
|
2024-10-27 12:23:21 -04:00
|
|
|
"[{}] [{:>5}] {}",
|
|
|
|
now.now().format("%Y-%m-%d %H:%M:%S%.6f"),
|
|
|
|
record.level(),
|
|
|
|
record.args()
|
2024-05-29 09:02:10 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2024-06-04 13:01:53 -04:00
|
|
|
Logger::try_with_str("WARN")
|
2024-05-29 09:02:10 -04:00
|
|
|
.expect("LogSpecification String has errors")
|
|
|
|
.print_message()
|
|
|
|
.log_to_stderr()
|
2024-10-27 12:23:21 -04:00
|
|
|
.add_writer("Alert", file_logger())
|
2024-05-29 09:02:10 -04:00
|
|
|
.start()
|
|
|
|
.unwrap();
|
|
|
|
|
2024-10-27 12:23:21 -04:00
|
|
|
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");
|
2024-05-29 09:02:10 -04:00
|
|
|
}
|