Skip to content

Commit

Permalink
chore: 使用 tracing 替换 env_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer committed May 1, 2024
1 parent d3bfca4 commit 908bb90
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
70 changes: 40 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ chrono = { version = "0.4.35", features = ["serde"] }
cookie = "0.18.0"
dirs = "5.0.1"
entity = { path = "entity" }
env_logger = "0.11.3"
filenamify = "0.1.0"
float-ord = "0.3.2"
futures = "0.3.30"
Expand Down Expand Up @@ -49,6 +48,8 @@ strum = { version = "0.26", features = ["derive"] }
thiserror = "1.0.58"
tokio = { version = "1", features = ["full"] }
toml = "0.8.12"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["chrono"] }

[workspace]
members = [".", "entity", "migration"]
Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[macro_use]
extern crate log;
extern crate tracing;

mod bilibili;
mod config;
Expand All @@ -8,8 +8,8 @@ mod database;
mod downloader;
mod error;

use env_logger::Env;
use once_cell::sync::Lazy;
use tracing_subscriber::util::SubscriberInitExt;

use crate::bilibili::BiliClient;
use crate::config::CONFIG;
Expand All @@ -18,7 +18,15 @@ use crate::database::{database_connection, migrate_database};

#[tokio::main]
async fn main() -> ! {
env_logger::init_from_env(Env::default().default_filter_or("None,bili_sync=info"));
let default_log_level = std::env::var("RUST_LOG").unwrap_or("None,bili_sync=info".to_owned());
tracing_subscriber::fmt::Subscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::builder().parse_lossy(default_log_level))
.with_timer(tracing_subscriber::fmt::time::ChronoLocal::new(
"%Y-%m-%d %H:%M:%S%.3f".to_owned(),
))
.finish()
.try_init()
.expect("初始化日志失败");
Lazy::force(&SCAN_ONLY);
Lazy::force(&CONFIG);
let mut anchor = chrono::Local::now().date_naive();
Expand Down

0 comments on commit 908bb90

Please sign in to comment.