Skip to content

Commit

Permalink
fix log display
Browse files Browse the repository at this point in the history
  • Loading branch information
ltitanb committed Jul 25, 2024
1 parent 5d4113f commit 5041f16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ serde_yaml = "0.9.33"

# telemetry
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
prometheus = "0.13.4"

# crypto
Expand Down
25 changes: 14 additions & 11 deletions crates/common/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
use std::time::{SystemTime, UNIX_EPOCH};

use alloy::{
primitives::U256,
Expand All @@ -10,7 +7,7 @@ use alloy::{
use blst::min_pk::{PublicKey, Signature};
use rand::{distributions::Alphanumeric, Rng};
use reqwest::header::HeaderMap;
use tracing::Level;
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

use crate::types::Chain;

Expand Down Expand Up @@ -101,14 +98,20 @@ pub mod as_eth_str {
// TODO: more customized logging + logging guard
pub fn initialize_tracing_log() {
let level_env = std::env::var("RUST_LOG").unwrap_or("info".to_owned());
let level = if let Ok(level) = Level::from_str(&level_env) {
level
} else {
eprint!("Invalid log level {}, defaulting to info", level_env);
Level::INFO

let filter = match level_env.parse::<EnvFilter>() {
Ok(f) => f,
Err(_) => {
eprintln!("Invalid RUST_LOG value {}, defaulting to info", level_env);
EnvFilter::new("info")
}
};

tracing_subscriber::fmt().with_max_level(level).with_target(false).init();
tracing_subscriber::registry()
.with(filter)
.with(fmt::layer().with_target(false))
.try_init()
.unwrap();
}

pub fn print_logo() {
Expand Down

0 comments on commit 5041f16

Please sign in to comment.