Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding tracing filter with RUST_LOG env var #1896

Merged
merged 6 commits into from
Feb 21, 2022
Merged

Conversation

romac
Copy link
Member

@romac romac commented Feb 21, 2022

Closes: #1895

Usage

With this PR, one can set the RUST_LOG variable to tendermint_rpc=debug,ibc_relayer=info,ibc_relayer_cli=info in order to enable debug output for tendermint-rpc and info output for the relayer.

RUST_LOG=tendermint_rpc=debug,ibc_relayer=info,ibc_relayer_cli=info hermes start

PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests: integration (for Hermes) or unit/mock tests (for modules).
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

Copy link
Member

@adizere adizere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left 2 questions, nothing serious.

.unwrap();
fn build_tracing_filter(log_level: LogLevel) -> Result<EnvFilter, FrameworkError> {
let directive = std::env::var(HERMES_LOG_VAR).unwrap_or_else(|_| {
let target_crates = ["ibc_relayer", "ibc_relayer_cli"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see here we're using RUST_LOG not only to replace the log level, but also the crates/modules. Can we give an example on how we're supposed to use RUST_LOG to overwrite the tracing parameters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, using RUST_LOG will override everything. I'll add an example, perhaps something like:

RUST_LOG=tendermint_rpc=debug,ibc_relayer=info,ibc_relayer_cli=info hermes start


use crate::config::Error;

/// The name of the environment variable through which one can override
/// the tracing filter built in [`build_tracing_filter`].
const HERMES_LOG_VAR: &str = "RUST_LOG";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall the integration tests framework making use of RUST_LOG, eg in cargo test. Would just like to flag that -- is there any interference between this approach and the pre-existing support for RUST_LOG in cargo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logs from the integration tests look fine to me: https://github.com/informalsystems/ibc-rs/runs/5272869928?check_suite_focus=true (modulo some doc tests failures, unrelated to this PR and best fixed elsewhere)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, just to clarify, cargo test does not care itself about RUST_LOG but the integration tests themselves do, cf. https://github.com/informalsystems/ibc-rs/blob/8329d856844df30651f68a25ca5c5db4addbaa2b/tools/integration-test/src/bootstrap/single.rs#L75

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the test suite does is look at the RUST_LOG env variable, and then sets the log_level property in config.toml to that. If the test suite is only ever run with RUST_LOG=info/trace/debug/error/warn then everything should work as expected with no change in the output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, just to clarify, cargo test does not care itself about RUST_LOG but the integration tests themselves do, cf.

Thanks for clarifying that! This part wasn't obvious to me.

@@ -33,7 +33,7 @@ impl Runnable for StartCmd {
let config = (*app_config()).clone();
let config = Arc::new(RwLock::new(config));

let supervisor_handle = make_supervisor::<ProdChainHandle>(config.clone(), self.full_scan)
let supervisor_handle = make_supervisor::<ProdChainHandle>(config, self.full_scan)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less cloning of massive data structures, good.

Copy link
Contributor

@seanchen1991 seanchen1991 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was just cloning an Arc though, so it should have just consisted of incrementing a reference count.

Copy link
Contributor

@mzabaluev mzabaluev Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It likely does not matter in the startup code, but in general coercing an Arc to a reference is still cheaper than atomically incrementing a ref count.

relayer-cli/src/components.rs Outdated Show resolved Hide resolved
relayer-cli/src/components.rs Outdated Show resolved Hide resolved
romac and others added 3 commits February 21, 2022 11:30
…`RUST_LOG` is set

Co-authored-by: Mikhail Zabaluev <mikhail@informal.systems>
Co-authored-by: Mikhail Zabaluev <mikhail@informal.systems>
Copy link
Member

@adizere adizere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but I still don't see any documentation on how to use RUST_LOG. Please remember to add that either in guide (release PR) or here.


use crate::config::Error;

/// The name of the environment variable through which one can override
/// the tracing filter built in [`build_tracing_filter`].
const HERMES_LOG_VAR: &str = "RUST_LOG";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, just to clarify, cargo test does not care itself about RUST_LOG but the integration tests themselves do, cf.

Thanks for clarifying that! This part wasn't obvious to me.

@romac romac merged commit b6a4b06 into master Feb 21, 2022
@romac romac deleted the romac/rust-log branch February 21, 2022 13:48
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
…ems#1896)

Closes: informalsystems#1895

With this PR, one can set the `RUST_LOG` variable to `tendermint_rpc=debug,ibc_relayer=info,ibc_relayer_cli=info` in order to enable debug output for `tendermint-rpc` and info output for the relayer.

```shell
RUST_LOG=tendermint_rpc=debug,ibc_relayer=info,ibc_relayer_cli=info hermes start
```

---

* Allow overriding tracing filter with `RUST_LOG` env var

* Fix warning

* Add changelog entry

* Rename `log_level` to `default_level` as the parameter is ignored if `RUST_LOG` is set

Co-authored-by: Mikhail Zabaluev <mikhail@informal.systems>

* Better log message

Co-authored-by: Mikhail Zabaluev <mikhail@informal.systems>

* Small refactor

Co-authored-by: Mikhail Zabaluev <mikhail@informal.systems>
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.

Allow overriding the tracing filter with the RUST_LOG environment variable
4 participants