add logger
This commit is contained in:
@@ -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
31
src/utils/logger.rs
Normal 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
1
src/utils/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod logger;
|
||||
Reference in New Issue
Block a user