Skip to content

Commit 1235a2d

Browse files
committed
Format logging | header art
1 parent a375cec commit 1235a2d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/config/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use log::{info, LevelFilter, trace};
99
use serde::Deserialize;
1010
use serde_json::Value;
1111
use tokio::runtime::{Builder, Runtime};
12+
use std::io::Write;
13+
use crate::config::time::current_formatted_time;
1214

1315
pub mod time;
1416

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

7678
pub fn init_configs (config_path : Option<&String>) -> std::io::Result<()> {
7779
//init logger
78-
env_logger::builder().filter_level(LevelFilter::Info).init();
80+
env_logger::builder()
81+
.format(|buf,rec| {
82+
let style = buf.default_level_style(rec.level());
83+
writeln!(buf, "[{} {style}{}{style:#} librespeed_rs] {}",current_formatted_time(),rec.level(), rec.args())
84+
})
85+
.filter_level(LevelFilter::Info).init();
86+
println!("{HEAD_ART}");
7987
//find server configs
8088
match config_path {
8189
Some(config_path) => {
@@ -190,4 +198,12 @@ pub static ROUTES: OnceLock<HashMap<String,&str>> = OnceLock::new();
190198
pub static GARBAGE_DATA: OnceLock<Vec<u8>> = OnceLock::new();
191199
pub static SERVER_CONFIG: OnceLock<ServerConfig> = OnceLock::new();
192200
pub static FONT: OnceLock<FontRef> = OnceLock::new();
193-
pub static DEF_ASSETS : Dir = include_dir!("assets");
201+
pub static DEF_ASSETS : Dir = include_dir!("assets");
202+
pub const HEAD_ART : &str = r#"
203+
_ _ _ _
204+
| (_) |__ _ __ ___ ___ _ __ ___ ___ __| | _ __ ___
205+
| | | '_ \| '__/ _ \/ __| '_ \ / _ \/ _ \/ _` |_____| '__/ __|
206+
| | | |_) | | | __/\__ \ |_) | __/ __/ (_| |_____| | \__ \
207+
|_|_|_.__/|_| \___||___/ .__/ \___|\___|\__,_| |_| |___/
208+
|_|
209+
"#;

src/config/time.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ pub fn convert_time_local (time : i64) -> String {
77
local.format("%Y-%m-%d %H:%M:%S").to_string()
88
}
99

10+
pub fn current_formatted_time() -> String {
11+
Local::now().format("%Y-%m-%d %H:%M:%S%.3f").to_string()
12+
}
13+
1014
#[allow(dead_code)]
1115
pub fn convert_time_utc (time : i64) -> String {
1216
let dt = DateTime::from_timestamp_millis(time).unwrap();

0 commit comments

Comments
 (0)