把log换成tracing

This commit is contained in:
shenjack-5600u 2024-01-29 23:35:08 +08:00
parent 5ebb5a0ee3
commit 789dd2494e
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
5 changed files with 13 additions and 29 deletions

View File

@ -27,12 +27,5 @@ sha1 = "0.10.6"
zstd = "0.13.0" zstd = "0.13.0"
log = "0.4.20" tracing = "0.1.40"
[dependencies.simple_logger] tracing-subscriber = { version = "0.3.18", features = ["time"] }
version = "4.3.3"
features = ["colors", "threads", "timestamps"]
# [dependencies.db_logger]
# version = "0.1"
# optional = true
# default-features = false
# features = ["postgres"]

View File

@ -2,7 +2,7 @@ use crate::config::Config;
use crate::utils::avro_data_to_file_list; use crate::utils::avro_data_to_file_list;
use crate::PROTOCOL_VERSION; use crate::PROTOCOL_VERSION;
use log::{info, warn}; use tracing::{info, instrument, warn};
use reqwest::{Client, StatusCode}; use reqwest::{Client, StatusCode};
use serde::Deserialize; use serde::Deserialize;
use zstd::stream::decode_all; use zstd::stream::decode_all;
@ -14,6 +14,7 @@ pub struct SyncFile {
pub size: i64, pub size: i64,
} }
#[derive(Debug, Clone)]
pub struct Cluster { pub struct Cluster {
pub config: Config, pub config: Config,
pub ua: String, pub ua: String,
@ -60,6 +61,7 @@ impl Cluster {
pub async fn get_file_list(&self) -> Option<Vec<SyncFile>> { pub async fn get_file_list(&self) -> Option<Vec<SyncFile>> {
// server: https://openbmclapi.bangbang93.com // server: https://openbmclapi.bangbang93.com
// path: /openbmclapi/files // path: /openbmclapi/files
info!("initing");
let url = self.config.join_center_url("/openbmclapi/files"); let url = self.config.join_center_url("/openbmclapi/files");
let password = self.config.cluster_secret.clone(); let password = self.config.cluster_secret.clone();
let username = self.config.cluster_id.clone(); let username = self.config.cluster_id.clone();

View File

@ -1,6 +1,6 @@
use { use {
crate::fatal, crate::fatal,
log::{info, warn}, tracing::{info, warn},
serde::{Deserialize, Serialize}, serde::{Deserialize, Serialize},
std::{ std::{
env, fs, env, fs,

View File

@ -1,22 +1,11 @@
use tracing_subscriber::FmtSubscriber;
pub fn init_log_with_cli() { pub fn init_log_with_cli() {
// 命令行参数 // 命令行参数
// --warn // --warn
// --debug // --debug
// --trace // --trace
// 从低级开始判断 // 从低级开始判断
let log_level;
if std::env::args().any(|x| x == "--trace") { tracing_subscriber::fmt::init();
log_level = log::LevelFilter::Trace;
} else if std::env::args().any(|x| x == "--debug") {
log_level = log::LevelFilter::Debug;
} else if std::env::args().any(|x| x == "--warn") {
log_level = log::LevelFilter::Warn;
} else {
log_level = log::LevelFilter::Info;
}
simple_logger::SimpleLogger::new()
.with_level(log_level)
.env()
.init()
.unwrap();
} }

View File

@ -3,7 +3,7 @@ use crate::cluster::SyncFile;
use std::io::Cursor; use std::io::Cursor;
use apache_avro::{from_avro_datum, from_value, types::Value}; use apache_avro::{from_avro_datum, from_value, types::Value};
use log::{info, warn}; use tracing::{info, warn};
use md5::{Digest, Md5}; use md5::{Digest, Md5};
use sha1::Sha1; use sha1::Sha1;
use std::path::PathBuf; use std::path::PathBuf;
@ -116,14 +116,14 @@ pub fn avro_data_to_file_list(data: Vec<u8>) -> Option<Vec<SyncFile>> {
macro_rules! fatal { macro_rules! fatal {
// 正常输入两组信息 // 正常输入两组信息
(($($arg1:tt)+), ($($arg2:tt)+)) => { (($($arg1:tt)+), ($($arg2:tt)+)) => {
use log::error; use tracing::error;
// error!() + panic!() // error!() + panic!()
error!($($arg1)+); error!($($arg1)+);
panic!($($arg2)+); panic!($($arg2)+);
}; };
// 如果只输入了一组 // 如果只输入了一组
($($arg:tt)+) => { ($($arg:tt)+) => {
use log::error; use tracing::error;
// error!() + panic!() // error!() + panic!()
error!($($arg)+); error!($($arg)+);
panic!($($arg)+); panic!($($arg)+);