ruwebframe 0.1.3

a simple webframe for rust actix-web, based on rudi and rbatis.
Documentation
use flexi_logger::{Cleanup, Criterion, FileSpec, Logger, Naming};

#[derive(Debug, Clone)]
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| {
                // 格式:[2026-08-01 14:30:25.123] [INFO] my_module:10 - message
                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), // 当文件达到 10 MB 时触发轮转[citation:3][citation:5][citation:6]
                Naming::Numbers,             // 旧文件使用数字编号命名
                Cleanup::KeepLogFiles(5),    // 只保留最近的 5 个日志文件[citation:8][citation:10]
            )
            .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)*) => {
        // 1. format! 拼接所有参数
        // 2. println! 到控制台
        // 3. log::info! 写入文件
        println!("{}", format!($($arg)*));
        log::info!("{}", format!($($arg)*));
    };
}
pub fn info2(msg1: &str, msg2: &str) -> () {
    rulog::find_bean_rulog();
    let msg = format!("{} {}", msg1, msg2);

    println!("{}", msg);
    log::info!("{}", msg);
}
pub fn error2(msg1: &str, msg2: &str) -> () {
    rulog::find_bean_rulog(); //get_log_config();
    let msg = format!("{} {}", msg1, msg2);

    println!("{}", msg);
    log::error!("{}", msg);
}
pub fn debug2(msg1: &str, msg2: &str) -> () {
    rulog::find_bean_rulog(); //get_log_config();
    let msg = format!("{} {}", msg1, msg2);

    println!("{}", msg);
    log::debug!("{}", msg);
}