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.
This commit is contained in:
Michael Sproul
2025-08-15 13:17:26 +10:00
committed by GitHub
parent 5ebb44e222
commit 42f6d7b02d
6 changed files with 15 additions and 55 deletions

View File

@@ -20,7 +20,6 @@ bls = { workspace = true }
clap = { workspace = true }
clap_utils = { workspace = true }
deposit_contract = { workspace = true }
env_logger = { workspace = true }
environment = { workspace = true }
eth2 = { workspace = true }
eth2_network_config = { workspace = true }

View File

@@ -18,12 +18,10 @@ use parse_ssz::run_parse_ssz;
use std::path::PathBuf;
use std::process;
use std::str::FromStr;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, util::SubscriberInitExt};
use types::{EthSpec, EthSpecId};
fn main() {
env_logger::init();
let matches = Command::new("Lighthouse CLI Tool")
.version(lighthouse_version::VERSION)
.display_order(0)
@@ -653,7 +651,7 @@ fn main() {
}
fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, matches: &ArgMatches) -> Result<(), String> {
let (env_builder, _file_logging_layer, _stdout_logging_layer, _sse_logging_layer_opt) =
let (env_builder, file_logging_layer, stdout_logging_layer, _sse_logging_layer_opt) =
env_builder
.multi_threaded_tokio_runtime()
.map_err(|e| format!("should start tokio runtime: {:?}", e))?
@@ -682,6 +680,18 @@ fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, matches: &ArgMatches) ->
.build()
.map_err(|e| format!("should build env: {:?}", e))?;
let mut logging_layers = vec![file_logging_layer];
if let Some(stdout) = stdout_logging_layer {
logging_layers.push(stdout);
}
let logging_result = tracing_subscriber::registry()
.with(logging_layers)
.try_init();
if let Err(e) = logging_result {
eprintln!("Failed to initialize logger: {e}");
}
// Determine testnet-dir path or network name depending on CLI flags.
let (testnet_dir, network_name) =
if let Some(testnet_dir) = parse_optional::<PathBuf>(matches, "testnet-dir")? {