From 5350e2942a655f1315193561efd13c7700c375b9 Mon Sep 17 00:00:00 2001 From: itsusinn Date: Sat, 5 Feb 2022 20:17:14 +0800 Subject: [PATCH] refactor: replace log with tracing --- Cargo.toml | 11 ++++++----- src/main.rs | 17 ++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a3f05b..cb8b5d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,9 @@ teloxide-core = { version = "0.3.3",default-features = false, features = ["rustl teloxide-macros = "0.4.1" # logging -env_logger = "0.9.0" -log = "0.4.14" +tracing="0.1.29" +tracing-subscriber = { version = "0.3.6", features = ["env-filter","tracing-log"]} +log="0.4.14" # serialization serde = { version = "1.0.130",default-features = false,features = ["derive","rc"] } @@ -56,9 +57,9 @@ reqwest = { version = "0.11.9" ,default-features = false ,features = ["rustls"," sled = "0.34.7" # mesagisto -nats = "0.16.0" -mesagisto-client = { rev = "68f0505", git = "https://github.com/MeowCat-Studio/mesagisto-client-rs.git"} -# mesagisto-client = { path = "../../mesagisto-client/rust" } +nats = "0.17.0" +# mesagisto-client = { rev = "414e33", git = "https://github.com/MeowCat-Studio/mesagisto-client-rs.git"} +mesagisto-client = { path = "../../mesagisto-client/rust" } automatic-config = { git = "https://github.com/Itsusinn/automatic-config-rs.git" } singleton = { git = "https://github.com/Itsusinn/singleton-rs.git", rev = "bee321c" } # singleton = { path = "/home/itsusinn/Workspace/Code/singleton-rs" } diff --git a/src/main.rs b/src/main.rs index f507351..454dd2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ #![allow(incomplete_features)] #![feature(backtrace, capture_disjoint_fields)] -use env_logger::TimestampPrecision; use futures::FutureExt; use mesagisto_client::MesagistoConfig; use std::sync::Arc; @@ -28,20 +27,16 @@ mod webhook; #[tokio::main] async fn main() { - - env_logger::builder() - .write_style(env_logger::WriteStyle::Auto) - .filter(None, log::LevelFilter::Error) - .format_timestamp(Some(TimestampPrecision::Seconds)) - .filter(Some("telegram_message_source"), log::LevelFilter::Info) - .filter(Some("mesagisto_client"), log::LevelFilter::Info) - .filter(Some("teloxide"), log::LevelFilter::Info) - .init(); - run().await.unwrap(); } #[allow(unused_must_use)] async fn run() -> Result<(), anyhow::Error> { + let env = tracing_subscriber::EnvFilter::from("warn") + .add_directive("teloxide=info".parse()?) + .add_directive("telegram_message_source=info".parse()?) + .add_directive("mesagisto_client=info".parse()?); + tracing_subscriber::fmt().with_env_filter(env).init(); + if !CONFIG.enable { log::warn!("Mesagisto-Bot is not enabled and is about to exit the program."); log::warn!("To enable it, please modify the configuration file.");