Skip to content

Commit 42f6d7b

Browse files
Yeet env_logger into the sun (#7872)
- Remove explicit `env_logger` usage from `state_processing` tests and `lcli`. - Set up tracing correctly for `lcli` (I've checked that we can see logs after this change). - I didn't do anything to set up logging for the `state_processing` tests, as these are rarely run manually (they never fail). We could add `test_logger` in there on an as-needed basis.
1 parent 5ebb44e commit 42f6d7b

File tree

6 files changed

+15
-55
lines changed

6 files changed

+15
-55
lines changed

Cargo.lock

Lines changed: 1 addition & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ dirs = "3"
136136
discv5 = { version = "0.9", features = ["libp2p"] }
137137
doppelganger_service = { path = "validator_client/doppelganger_service" }
138138
either = "1.9"
139-
env_logger = "0.9"
140139
environment = { path = "lighthouse/environment" }
141140
eth2 = { path = "common/eth2" }
142141
eth2_config = { path = "common/eth2_config" }

consensus/state_processing/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ types = { workspace = true }
4141

4242
[dev-dependencies]
4343
beacon_chain = { workspace = true }
44-
env_logger = { workspace = true }
4544
tokio = { workspace = true }

consensus/state_processing/src/per_epoch_processing/tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ use crate::per_epoch_processing::process_epoch;
33
use beacon_chain::test_utils::BeaconChainHarness;
44
use beacon_chain::types::{EthSpec, MinimalEthSpec};
55
use bls::{FixedBytesExtended, Hash256};
6-
use env_logger::{Builder, Env};
76
use types::Slot;
87

98
#[tokio::test]
109
async fn runs_without_error() {
11-
Builder::from_env(Env::default().default_filter_or("error")).init();
12-
1310
let harness = BeaconChainHarness::builder(MinimalEthSpec)
1411
.default_spec()
1512
.deterministic_keypairs(8)

lcli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ bls = { workspace = true }
2020
clap = { workspace = true }
2121
clap_utils = { workspace = true }
2222
deposit_contract = { workspace = true }
23-
env_logger = { workspace = true }
2423
environment = { workspace = true }
2524
eth2 = { workspace = true }
2625
eth2_network_config = { workspace = true }

lcli/src/main.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ use parse_ssz::run_parse_ssz;
1818
use std::path::PathBuf;
1919
use std::process;
2020
use std::str::FromStr;
21-
use tracing_subscriber::filter::LevelFilter;
21+
use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, util::SubscriberInitExt};
2222
use types::{EthSpec, EthSpecId};
2323

2424
fn main() {
25-
env_logger::init();
26-
2725
let matches = Command::new("Lighthouse CLI Tool")
2826
.version(lighthouse_version::VERSION)
2927
.display_order(0)
@@ -653,7 +651,7 @@ fn main() {
653651
}
654652

655653
fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, matches: &ArgMatches) -> Result<(), String> {
656-
let (env_builder, _file_logging_layer, _stdout_logging_layer, _sse_logging_layer_opt) =
654+
let (env_builder, file_logging_layer, stdout_logging_layer, _sse_logging_layer_opt) =
657655
env_builder
658656
.multi_threaded_tokio_runtime()
659657
.map_err(|e| format!("should start tokio runtime: {:?}", e))?
@@ -682,6 +680,18 @@ fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, matches: &ArgMatches) ->
682680
.build()
683681
.map_err(|e| format!("should build env: {:?}", e))?;
684682

683+
let mut logging_layers = vec![file_logging_layer];
684+
if let Some(stdout) = stdout_logging_layer {
685+
logging_layers.push(stdout);
686+
}
687+
let logging_result = tracing_subscriber::registry()
688+
.with(logging_layers)
689+
.try_init();
690+
691+
if let Err(e) = logging_result {
692+
eprintln!("Failed to initialize logger: {e}");
693+
}
694+
685695
// Determine testnet-dir path or network name depending on CLI flags.
686696
let (testnet_dir, network_name) =
687697
if let Some(testnet_dir) = parse_optional::<PathBuf>(matches, "testnet-dir")? {

0 commit comments

Comments
 (0)