mirror of
https://github.com/DefectingCat/rua-list
synced 2025-07-15 16:51:31 +00:00
Remove useless files
This commit is contained in:
@ -3,6 +3,7 @@ use anyhow::Result;
|
||||
use axum::http;
|
||||
use log::{debug, info};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RUAService {
|
||||
Get,
|
||||
Post,
|
||||
|
@ -1,76 +0,0 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use std::{io::Write, path::Path};
|
||||
|
||||
use anyhow::Result;
|
||||
use chrono::Local;
|
||||
use env_logger::{Builder, Env};
|
||||
use tokio::{
|
||||
fs::{self, OpenOptions},
|
||||
io::AsyncWriteExt,
|
||||
};
|
||||
|
||||
use crate::config::Config;
|
||||
|
||||
pub async fn create_folder(file_path: &Path) -> Result<()> {
|
||||
if file_path.exists() {
|
||||
return Ok(());
|
||||
} else {
|
||||
fs::create_dir_all(
|
||||
file_path
|
||||
.parent()
|
||||
.expect("Can not access log parent folder"),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn init_logger(config: &Config) -> Result<()> {
|
||||
let log_path = if let Some(path) = config.log_path.to_owned() {
|
||||
path
|
||||
} else {
|
||||
eprintln!("Can not read log path from config");
|
||||
exit(1);
|
||||
};
|
||||
let log_level = if let Some(level) = config.log_level.to_owned() {
|
||||
level
|
||||
} else {
|
||||
eprintln!("Can not read log level from config");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
let now = Local::now();
|
||||
let formatted = format!("{}.log", now.format("%Y-%m-%d"));
|
||||
let file_path = PathBuf::from(&log_path).join(formatted);
|
||||
create_folder(&file_path).await?;
|
||||
|
||||
let env = Env::default().filter_or("RUA_LOG_LEVEL", &log_level);
|
||||
let mut builder = Builder::from_env(env);
|
||||
|
||||
builder
|
||||
.format(move |buf, record| {
|
||||
let formatted = format!("{}", now.format("%Y-%m-%d %H:%M:%S"));
|
||||
let log = format!("{} - {} - {}", formatted, record.level(), record.args());
|
||||
writeln!(buf, "{log}")?;
|
||||
|
||||
let file_path = file_path.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.read(true)
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&file_path)
|
||||
.await
|
||||
.expect("Can not write log file");
|
||||
file.write_all(format!("{log}\n").as_bytes())
|
||||
.await
|
||||
.expect("Can not write log file");
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.init();
|
||||
|
||||
Ok(())
|
||||
}
|
@ -20,7 +20,6 @@ mod consts;
|
||||
mod error;
|
||||
mod header_parser;
|
||||
mod http_client;
|
||||
mod logger;
|
||||
mod middlewares;
|
||||
mod routes;
|
||||
|
||||
@ -28,10 +27,6 @@ mod routes;
|
||||
async fn main() -> Result<()> {
|
||||
let config = Config::build();
|
||||
|
||||
// if let Err(err) = logger::init_logger(&config).await {
|
||||
// error!("Failed to create logger; {}", err.to_string());
|
||||
// exit(1);
|
||||
// }
|
||||
tracing_subscriber::fmt()
|
||||
.compact()
|
||||
.with_file(false)
|
||||
|
Reference in New Issue
Block a user