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

46
Cargo.lock generated
View File

@@ -709,17 +709,6 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]] [[package]]
name = "auto_impl" name = "auto_impl"
version = "0.5.0" version = "0.5.0"
@@ -2743,19 +2732,6 @@ dependencies = [
"regex", "regex",
] ]
[[package]]
name = "env_logger"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]] [[package]]
name = "environment" name = "environment"
version = "0.1.2" version = "0.1.2"
@@ -4054,15 +4030,6 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.9" version = "0.3.9"
@@ -5058,7 +5025,6 @@ dependencies = [
"clap", "clap",
"clap_utils", "clap_utils",
"deposit_contract", "deposit_contract",
"env_logger 0.9.3",
"environment", "environment",
"eth2", "eth2",
"eth2_network_config", "eth2_network_config",
@@ -7491,7 +7457,7 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6"
dependencies = [ dependencies = [
"env_logger 0.8.4", "env_logger",
"log", "log",
"rand 0.8.5", "rand 0.8.5",
] ]
@@ -8961,7 +8927,6 @@ dependencies = [
"beacon_chain", "beacon_chain",
"bls", "bls",
"derivative", "derivative",
"env_logger 0.9.3",
"ethereum_hashing", "ethereum_hashing",
"ethereum_ssz", "ethereum_ssz",
"ethereum_ssz_derive", "ethereum_ssz_derive",
@@ -9262,15 +9227,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "termcolor"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "terminal_size" name = "terminal_size"
version = "0.4.2" version = "0.4.2"

View File

@@ -136,7 +136,6 @@ dirs = "3"
discv5 = { version = "0.9", features = ["libp2p"] } discv5 = { version = "0.9", features = ["libp2p"] }
doppelganger_service = { path = "validator_client/doppelganger_service" } doppelganger_service = { path = "validator_client/doppelganger_service" }
either = "1.9" either = "1.9"
env_logger = "0.9"
environment = { path = "lighthouse/environment" } environment = { path = "lighthouse/environment" }
eth2 = { path = "common/eth2" } eth2 = { path = "common/eth2" }
eth2_config = { path = "common/eth2_config" } eth2_config = { path = "common/eth2_config" }

View File

@@ -41,5 +41,4 @@ types = { workspace = true }
[dev-dependencies] [dev-dependencies]
beacon_chain = { workspace = true } beacon_chain = { workspace = true }
env_logger = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }

View File

@@ -3,13 +3,10 @@ use crate::per_epoch_processing::process_epoch;
use beacon_chain::test_utils::BeaconChainHarness; use beacon_chain::test_utils::BeaconChainHarness;
use beacon_chain::types::{EthSpec, MinimalEthSpec}; use beacon_chain::types::{EthSpec, MinimalEthSpec};
use bls::{FixedBytesExtended, Hash256}; use bls::{FixedBytesExtended, Hash256};
use env_logger::{Builder, Env};
use types::Slot; use types::Slot;
#[tokio::test] #[tokio::test]
async fn runs_without_error() { async fn runs_without_error() {
Builder::from_env(Env::default().default_filter_or("error")).init();
let harness = BeaconChainHarness::builder(MinimalEthSpec) let harness = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec() .default_spec()
.deterministic_keypairs(8) .deterministic_keypairs(8)

View File

@@ -20,7 +20,6 @@ bls = { workspace = true }
clap = { workspace = true } clap = { workspace = true }
clap_utils = { workspace = true } clap_utils = { workspace = true }
deposit_contract = { workspace = true } deposit_contract = { workspace = true }
env_logger = { workspace = true }
environment = { workspace = true } environment = { workspace = true }
eth2 = { workspace = true } eth2 = { workspace = true }
eth2_network_config = { 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::path::PathBuf;
use std::process; use std::process;
use std::str::FromStr; use std::str::FromStr;
use tracing_subscriber::filter::LevelFilter; use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, util::SubscriberInitExt};
use types::{EthSpec, EthSpecId}; use types::{EthSpec, EthSpecId};
fn main() { fn main() {
env_logger::init();
let matches = Command::new("Lighthouse CLI Tool") let matches = Command::new("Lighthouse CLI Tool")
.version(lighthouse_version::VERSION) .version(lighthouse_version::VERSION)
.display_order(0) .display_order(0)
@@ -653,7 +651,7 @@ fn main() {
} }
fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, matches: &ArgMatches) -> Result<(), String> { 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 env_builder
.multi_threaded_tokio_runtime() .multi_threaded_tokio_runtime()
.map_err(|e| format!("should start tokio runtime: {:?}", e))? .map_err(|e| format!("should start tokio runtime: {:?}", e))?
@@ -682,6 +680,18 @@ fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, matches: &ArgMatches) ->
.build() .build()
.map_err(|e| format!("should build env: {:?}", e))?; .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. // Determine testnet-dir path or network name depending on CLI flags.
let (testnet_dir, network_name) = let (testnet_dir, network_name) =
if let Some(testnet_dir) = parse_optional::<PathBuf>(matches, "testnet-dir")? { if let Some(testnet_dir) = parse_optional::<PathBuf>(matches, "testnet-dir")? {