把log换成tracing
This commit is contained in:
parent
5ebb5a0ee3
commit
789dd2494e
11
Cargo.toml
11
Cargo.toml
@ -27,12 +27,5 @@ sha1 = "0.10.6"
|
||||
|
||||
zstd = "0.13.0"
|
||||
|
||||
log = "0.4.20"
|
||||
[dependencies.simple_logger]
|
||||
version = "4.3.3"
|
||||
features = ["colors", "threads", "timestamps"]
|
||||
# [dependencies.db_logger]
|
||||
# version = "0.1"
|
||||
# optional = true
|
||||
# default-features = false
|
||||
# features = ["postgres"]
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["time"] }
|
||||
|
@ -2,7 +2,7 @@ use crate::config::Config;
|
||||
use crate::utils::avro_data_to_file_list;
|
||||
use crate::PROTOCOL_VERSION;
|
||||
|
||||
use log::{info, warn};
|
||||
use tracing::{info, instrument, warn};
|
||||
use reqwest::{Client, StatusCode};
|
||||
use serde::Deserialize;
|
||||
use zstd::stream::decode_all;
|
||||
@ -14,6 +14,7 @@ pub struct SyncFile {
|
||||
pub size: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Cluster {
|
||||
pub config: Config,
|
||||
pub ua: String,
|
||||
@ -60,6 +61,7 @@ impl Cluster {
|
||||
pub async fn get_file_list(&self) -> Option<Vec<SyncFile>> {
|
||||
// server: https://openbmclapi.bangbang93.com
|
||||
// path: /openbmclapi/files
|
||||
info!("initing");
|
||||
let url = self.config.join_center_url("/openbmclapi/files");
|
||||
let password = self.config.cluster_secret.clone();
|
||||
let username = self.config.cluster_id.clone();
|
||||
|
@ -1,6 +1,6 @@
|
||||
use {
|
||||
crate::fatal,
|
||||
log::{info, warn},
|
||||
tracing::{info, warn},
|
||||
serde::{Deserialize, Serialize},
|
||||
std::{
|
||||
env, fs,
|
||||
|
19
src/log.rs
19
src/log.rs
@ -1,22 +1,11 @@
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
pub fn init_log_with_cli() {
|
||||
// 命令行参数
|
||||
// --warn
|
||||
// --debug
|
||||
// --trace
|
||||
// 从低级开始判断
|
||||
let log_level;
|
||||
if std::env::args().any(|x| x == "--trace") {
|
||||
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();
|
||||
|
||||
tracing_subscriber::fmt::init();
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use crate::cluster::SyncFile;
|
||||
use std::io::Cursor;
|
||||
|
||||
use apache_avro::{from_avro_datum, from_value, types::Value};
|
||||
use log::{info, warn};
|
||||
use tracing::{info, warn};
|
||||
use md5::{Digest, Md5};
|
||||
use sha1::Sha1;
|
||||
use std::path::PathBuf;
|
||||
@ -116,14 +116,14 @@ pub fn avro_data_to_file_list(data: Vec<u8>) -> Option<Vec<SyncFile>> {
|
||||
macro_rules! fatal {
|
||||
// 正常输入两组信息
|
||||
(($($arg1:tt)+), ($($arg2:tt)+)) => {
|
||||
use log::error;
|
||||
use tracing::error;
|
||||
// error!() + panic!()
|
||||
error!($($arg1)+);
|
||||
panic!($($arg2)+);
|
||||
};
|
||||
// 如果只输入了一组
|
||||
($($arg:tt)+) => {
|
||||
use log::error;
|
||||
use tracing::error;
|
||||
// error!() + panic!()
|
||||
error!($($arg)+);
|
||||
panic!($($arg)+);
|
||||
|
Loading…
Reference in New Issue
Block a user