Skip to content

Commit

Permalink
Format logging | header art
Browse files Browse the repository at this point in the history
  • Loading branch information
SudoDios committed Sep 12, 2024
1 parent a375cec commit 1235a2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use log::{info, LevelFilter, trace};
use serde::Deserialize;
use serde_json::Value;
use tokio::runtime::{Builder, Runtime};
use std::io::Write;
use crate::config::time::current_formatted_time;

pub mod time;

Expand Down Expand Up @@ -75,7 +77,13 @@ pub fn init_runtime () -> std::io::Result<Runtime> {

pub fn init_configs (config_path : Option<&String>) -> std::io::Result<()> {
//init logger
env_logger::builder().filter_level(LevelFilter::Info).init();
env_logger::builder()
.format(|buf,rec| {
let style = buf.default_level_style(rec.level());
writeln!(buf, "[{} {style}{}{style:#} librespeed_rs] {}",current_formatted_time(),rec.level(), rec.args())
})
.filter_level(LevelFilter::Info).init();
println!("{HEAD_ART}");
//find server configs
match config_path {
Some(config_path) => {
Expand Down Expand Up @@ -190,4 +198,12 @@ pub static ROUTES: OnceLock<HashMap<String,&str>> = OnceLock::new();
pub static GARBAGE_DATA: OnceLock<Vec<u8>> = OnceLock::new();
pub static SERVER_CONFIG: OnceLock<ServerConfig> = OnceLock::new();
pub static FONT: OnceLock<FontRef> = OnceLock::new();
pub static DEF_ASSETS : Dir = include_dir!("assets");
pub static DEF_ASSETS : Dir = include_dir!("assets");
pub const HEAD_ART : &str = r#"
_ _ _ _
| (_) |__ _ __ ___ ___ _ __ ___ ___ __| | _ __ ___
| | | '_ \| '__/ _ \/ __| '_ \ / _ \/ _ \/ _` |_____| '__/ __|
| | | |_) | | | __/\__ \ |_) | __/ __/ (_| |_____| | \__ \
|_|_|_.__/|_| \___||___/ .__/ \___|\___|\__,_| |_| |___/
|_|
"#;
4 changes: 4 additions & 0 deletions src/config/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pub fn convert_time_local (time : i64) -> String {
local.format("%Y-%m-%d %H:%M:%S").to_string()
}

pub fn current_formatted_time() -> String {
Local::now().format("%Y-%m-%d %H:%M:%S%.3f").to_string()
}

#[allow(dead_code)]
pub fn convert_time_utc (time : i64) -> String {
let dt = DateTime::from_timestamp_millis(time).unwrap();
Expand Down

0 comments on commit 1235a2d

Please sign in to comment.