Skip to content

feat: add a --log-level flag - #946

Open
yash251 wants to merge 1 commit into
lambdaclass:mainfrom
yash251:yash/821-log-level-flag
Open

yash251 wants to merge 1 commit into
lambdaclass:mainfrom
yash251:yash/821-log-level-flag

Conversation

@yash251

@yash251 yash251 commented Nov 30, 2026 •

Copy link
Copy Markdown

🗒️ Description / Motivation

  • Adds --log-level <error|warn|info|debug|trace> to node, beacon and validator.
  • Until now the log level could only be set through RUST_LOG, so it did not show up in --help, and launchers that only build a command line (ethereum-package, docker-compose, systemd units) had to set an environment variable instead.
  • The flag sets the floor that node_log_filter hard-coded as info. RUST_LOG still layers per-target directives on top of it, and the gossipsub cap stays unless a directive names that target.

What Changed

  • bin/ethlambda/src/cli.rs: --log-level on CommonOptions (so node and beacon both get it), plus the LOG_LEVELS list of accepted values.
  • bin/ethlambda/src/validator.rs: the same flag on ValidatorOptions.
  • bin/ethlambda/src/main.rs: init_node_logging and node_log_filter take the flag's value. The three sub-commands pass it in.
  • bin/ethlambda/src/command.rs: a parse test for the three sub-commands.
  • docs/cli.md: a row in the common flag table and in the validator flag table.

Correctness / Behavior Guarantees

  • Without the flag, nothing changes. The directive string built for every RUST_LOG value is the same as before, apart from a leading empty directive that the parser skips. The three existing filter tests pass unchanged.
  • With the flag, the directives are <level>,libp2p_gossipsub=error,<RUST_LOG>. So:
    • --log-level debug logs everything at DEBUG, with gossipsub still capped at ERROR.
    • --log-level debug with RUST_LOG=ethlambda_p2p=trace keeps the DEBUG floor and adds TRACE for that crate.
    • RUST_LOG=libp2p_gossipsub=warn still lifts the cap.
    • A bare level in RUST_LOG (for example RUST_LOG=warn) replaces the flag's level, the same way it replaces the default info today.
  • One point to confirm: when the flag is absent and RUST_LOG holds only per-target directives, the floor is still replaced, as rust_log_without_a_floor_still_replaces_it pins today. I kept that so this PR changes no existing behavior. If you would rather have info always apply as the floor, it is a one-line change and I am happy to make it.
  • The flag is an Option, so --help lists the possible values and the doc comment states the info default.
  • Values other than the five level names are rejected by clap at parse time.
  • No new dependencies.

Tests Added / Run

Added:

  • log_level_sets_the_floor_and_keeps_the_gossipsub_cap (main.rs): debug lets DEBUG through and keeps gossipsub warnings out. warn drops INFO and keeps gossipsub errors.
  • rust_log_layers_on_top_of_the_log_level_floor (main.rs): --log-level debug with RUST_LOG=libp2p_gossipsub=warn keeps the DEBUG floor and lifts the cap.
  • the_long_running_sub_commands_take_a_log_level (command.rs): node, beacon and validator each accept --log-level debug and reject --log-level verbose.

Commands run:

  • cargo test --locked -p ethlambda: 363 passed, 0 failed, 4 ignored, plus the two integration test binaries (1 passed each).
  • cargo test --locked --profile release-fast -p ethlambda --features ethlambda/include-ethrex (the binary's part of make test-ethrex): 371 passed, 0 failed, 4 ignored, plus the two integration test binaries.
  • With the flag's value ignored inside node_log_filter, the two new filter tests fail. With the change they pass.
  • make fmt: clean.
  • make lint: clean, all passes.
  • I did not run the whole make test locally. The change is confined to bin/ethlambda, so I ran that package's tests as above and left the last box unticked for CI.

Related Issues / PRs

✅ Verification Checklist

  • Ran make fmt - clean
  • Ran make lint (clippy with -D warnings) - clean
  • Ran make test (test-consensus, test-node and test-ethrex, at release-fast) - all passing

node, beacon and validator take --log-level <error|warn|info|debug|trace>.
It sets the floor node_log_filter hard-coded as info. RUST_LOG still adds
per-target directives on top of it, and the gossipsub cap stays unless a
directive names that target. Without the flag nothing changes.

Closes lambdaclass#821
@yash251
yash251 force-pushed the yash/821-log-level-flag branch from 1f75fc6 to 3fecdd4 Compare December 2, 2026 07:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a --log-level flag instead of configuring logs through RUST_LOG only

1 participant