36 lines
1.1 KiB
Rust
36 lines
1.1 KiB
Rust
// 版权所有 (c) ling 保留所有权利。
|
||
// 除非另行说明,否则仅允许在LingTransmit中使用此文件中的代码。
|
||
//
|
||
// 由 ling 创建于 2025/2/23.
|
||
#![allow(non_snake_case)]
|
||
|
||
use chrono::Local;
|
||
use colored::{Color, Colorize};
|
||
use fern::Dispatch;
|
||
use log::{Level, LevelFilter};
|
||
|
||
pub fn init_log() {
|
||
let console_dispatch = Dispatch::new()
|
||
.format(|out, message, record| {
|
||
let (title, color) = match record.level() {
|
||
Level::Error => ("Error", Color::Red),
|
||
Level::Warn => ("Warning", Color::Yellow),
|
||
Level::Info => ("Info", Color::Green),
|
||
Level::Debug => ("Debug", Color::BrightWhite),
|
||
Level::Trace => ("Trace", Color::White),
|
||
};
|
||
|
||
out.finish(format_args!(
|
||
"{}",
|
||
format!("[{} {}]\t{}", get_time(), title, message).color(color)
|
||
))
|
||
})
|
||
.chain(std::io::stdout())
|
||
.level(LevelFilter::Trace)
|
||
.apply();
|
||
}
|
||
|
||
fn get_time() -> String {
|
||
let now = Local::now();
|
||
now.format("%Y-%m-%d %H:%M:%S").to_string()
|
||
} |