chore: deps + refactor logging code

This commit is contained in:
Jun Kurihara 2024-05-21 02:11:27 +09:00
commit 9fdb378d32
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
4 changed files with 26 additions and 24 deletions

View file

@ -26,9 +26,9 @@ rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [
"sticky-cookie", "sticky-cookie",
] } ] }
anyhow = "1.0.82" anyhow = "1.0.86"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
serde = { version = "1.0.199", default-features = false, features = ["derive"] } serde = { version = "1.0.202", default-features = false, features = ["derive"] }
derive_builder = "0.20.0" derive_builder = "0.20.0"
tokio = { version = "1.37.0", default-features = false, features = [ tokio = { version = "1.37.0", default-features = false, features = [
"net", "net",
@ -43,7 +43,7 @@ mimalloc = { version = "*", default-features = false }
# config # config
clap = { version = "4.5.4", features = ["std", "cargo", "wrap_help"] } clap = { version = "4.5.4", features = ["std", "cargo", "wrap_help"] }
toml = { version = "0.8.12", default-features = false, features = ["parse"] } toml = { version = "0.8.13", default-features = false, features = ["parse"] }
hot_reload = "0.1.5" hot_reload = "0.1.5"
# logging # logging

View file

@ -1,28 +1,30 @@
use std::str::FromStr;
use tracing_subscriber::{fmt, prelude::*};
#[allow(unused)] #[allow(unused)]
pub use tracing::{debug, error, info, warn}; pub use tracing::{debug, error, info, warn};
/// Initialize the logger with the RUST_LOG environment variable.
pub fn init_logger() { pub fn init_logger() {
use tracing_subscriber::{fmt, prelude::*, EnvFilter}; let level_string = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string());
let level = tracing::Level::from_str(level_string.as_str()).unwrap_or(tracing::Level::INFO);
let format_layer = fmt::layer() // This limits the logger to emits only this crate with any level, for included crates it will emit only INFO or above level.
.with_line_number(false) let stdio_layer = fmt::layer()
.with_line_number(true)
.with_thread_ids(false) .with_thread_ids(false)
.with_target(false)
.with_thread_names(true) .with_thread_names(true)
.with_target(true) .with_target(true)
.with_level(true) .with_level(true)
.compact(); .compact()
.with_filter(tracing_subscriber::filter::filter_fn(move |metadata| {
(metadata
.target()
.starts_with(env!("CARGO_PKG_NAME").replace('-', "_").as_str())
&& metadata.level() <= &level)
|| metadata.level() <= &tracing::Level::INFO.min(level)
}));
// This limits the logger to emits only proxy crate let reg = tracing_subscriber::registry().with(stdio_layer);
let pkg_name = env!("CARGO_PKG_NAME").replace('-', "_"); reg.init();
let level_string = std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or_else(|_| "info".to_string());
let filter_layer = EnvFilter::new(format!("{}={}", pkg_name, level_string));
// let filter_layer = EnvFilter::try_from_default_env()
// .unwrap_or_else(|_| EnvFilter::new("info"))
// .add_directive(format!("{}=trace", pkg_name).parse().unwrap());
tracing_subscriber::registry()
.with(format_layer)
.with(filter_layer)
.init();
} }

View file

@ -46,8 +46,8 @@ pin-project-lite = "0.2.14"
async-trait = "0.1.80" async-trait = "0.1.80"
# Error handling # Error handling
anyhow = "1.0.82" anyhow = "1.0.86"
thiserror = "1.0.59" thiserror = "1.0.61"
# http for both server and client # http for both server and client
http = "1.1.0" http = "1.1.0"
@ -103,7 +103,7 @@ chrono = { version = "0.4.38", default-features = false, features = [
"alloc", "alloc",
"clock", "clock",
], optional = true } ], optional = true }
base64 = { version = "0.22.0", optional = true } base64 = { version = "0.22.1", optional = true }
[dev-dependencies] [dev-dependencies]

@ -1 +1 @@
Subproject commit c11410c76e738a62e62e7766b82f814547621f6f Subproject commit b44edeb60d234d49c45828395108f7519a048d4b