add logger

This commit is contained in:
2026-03-28 19:04:11 +08:00
parent 895a301ace
commit b24ab91860
5 changed files with 247 additions and 1 deletions

View File

@@ -8,6 +8,9 @@ use askama::Template;
mod config;
use crate::config::Config;
mod utils;
use utils::logger;
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {
@@ -43,7 +46,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Загружаем конфиг
let cfg = Config::load("config.yaml")?;
let addr = format!("{}:{}", cfg.host, cfg.port);
println!("dash.core is running on {}", addr);
logger::success(format!("Running on {}", addr), "Core");
// Build our application with routes
let app = Router::new()

31
src/utils/logger.rs Normal file
View File

@@ -0,0 +1,31 @@
use chrono::Local;
pub fn debug(msg: String, module: &str) {
let time_str = Local::now().format("%H:%M:%S").to_string();
println!("\x1b[34m[{}]\x1b[0m [{}/DEBUG]: {}", time_str, module, msg);
}
pub fn info(msg: String, module: &str) {
let time_str = Local::now().format("%H:%M:%S").to_string();
println!("\x1b[34m[{}]\x1b[0m [{}/INFO]: {}", time_str, module, msg);
}
pub fn success(msg: String, module: &str) {
let time_str = Local::now().format("%H:%M:%S").to_string();
println!("\x1b[34m[{}] \x1b[32m[{}/SUCCESS]:\x1b[0m {}", time_str, module, msg);
}
pub fn warn(msg: String, module: &str) {
let time_str = Local::now().format("%H:%M:%S").to_string();
println!("\x1b[34m[{}] \x1b[33m[{}/WARN]:\x1b[0m {}", time_str, module, msg);
}
pub fn error(msg: String, module: &str) {
let time_str = Local::now().format("%H:%M:%S").to_string();
println!("\x1b[34m[{}] \x1b[31m[{}/ERROR]:\x1b[0m {}", time_str, module, msg);
}
pub fn fatal(msg: String, module: &str) {
let time_str = Local::now().format("%H:%M:%S").to_string();
println!("\x1b[34m[{}] \x1b[1;31m[{}/FATAL]:\x1b[0m {}", time_str, module, msg);
}

1
src/utils/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod logger;