use flexi_logger::{Cleanup, Criterion, FileSpec, Logger, Naming};
pub struct RuLog {}
impl ruentity::BaseEntitySingle for RuLog {}
impl RuLog {
pub fn new() -> RuLog {
get_log_config();
RuLog {}
}
}
impl RuLog {
pub fn info(&self, msg: &str) {
println!("{}", msg);
}
}
use crate::rubase::ruentity;
use crate::rulog;
use std::sync::OnceLock;
static CONFIG: OnceLock<String> = OnceLock::new();
fn get_log_config() -> &'static String {
CONFIG.get_or_init(|| {
let _r = Logger::try_with_str("info")
.unwrap()
.log_to_file(
FileSpec::default()
.directory("./logs") .basename("app") .suppress_timestamp()
.suffix(".log"), )
.append()
.format(|w, now, record| {
write!(
w,
"[{}] [{}] {}:{} - {}",
now.format("%Y-%m-%d %H:%M:%S%.3f"),
record.level(),
record.module_path().unwrap_or("unknown"),
record.line().unwrap_or(0),
record.args()
)
})
.rotate(
Criterion::Size(50_000_000), Naming::Numbers, Cleanup::KeepLogFiles(5), )
.start();
return String::from("init log");
})
}
pub fn info(msg: &str) -> () {
get_log_config();
println!("{}", msg);
log::info!("{}", msg)
}
pub fn error(msg: &str) {
get_log_config();
println!("{}", msg);
log::error!("{}", msg)
}
pub fn debug(msg: &str) {
get_log_config();
println!("{}", msg);
log::debug!("{}", msg)
}
macro_rules! info {
($($arg:tt)*) => {
println!("{}", format!($($arg)*));
log::info!("{}", format!($($arg)*));
};
}
pub fn info2(msg1: &str, msg2: &str) -> () {
rulog::find_bean_ru_config(); let msg = format!("{} {}", msg1, msg2);
println!("{}", msg);
log::info!("{}", msg);
}
pub fn error2(msg1: &str, msg2: &str) -> () {
rulog::find_bean_ru_config(); let msg = format!("{} {}", msg1, msg2);
println!("{}", msg);
log::error!("{}", msg);
}
pub fn debug2(msg1: &str, msg2: &str) -> () {
rulog::find_bean_ru_config(); let msg = format!("{} {}", msg1, msg2);
println!("{}", msg);
log::debug!("{}", msg);
}