Cargo: Ability to set the RUST_LOG level in cargo run and cargo test commands.

Created on 8 Nov 2014  路  9Comments  路  Source: rust-lang/cargo

Consider the $cargo test case. While working on unit tests, when some of the tests fail, I need to dig deeper and understand exactly what went wrong. In the absence of a debugger, the log messages can be quite useful. I would like to leave out the debug!() messages in the source code. I would like to run the $cargo test for the specific test case under consider, with debug log level on.

Since cargo runs the executable, hence it can change the environment variable RUST_LOG easily based on some command line parameter. This would speed up the test, debug, fix, test cycle.

I am on Windows and working with environment variables from command line requires more work than the convenience available in Linux shell environments.

Reference to the question I raised in stack overflow: http://stackoverflow.com/questions/26804441/how-to-set-logging-level-while-running-cargo-test-in-rust

Most helpful comment

Very far from ideal, but worked for me right now. I've used std::env::set_var("RUST_LOG", "trace"); at the beginning of my test

All 9 comments

We should pass through RUST_LOG from the top level, so would you just want a more convenient method of setting this environment variable?

Yeah, he wants it so that it's easier to use for Windows (where env vars are harder to work with)

I don't think that cargo will provide a special way to set environment variables as RUST_LOG isn't necessarily any more special than any other environment variables, so closing this.

When I set RUST_LOG I get huge logs from compiler (lexer?) before logs from the test itself.
I don't see a way to avoid that.

RUST_LOG is to be set at runtime of the program you wish to debug.

(Also you can filter by crate and debug level with the variable.)

What should I do instead of:
$ RUST_LOG=debug cargo test
which spams compilation debugging logs ?

RUST_LOG=debug:crate::mod::mod::mod for some random module or crate you wish to see the log of

Oooohhhhh. Big thanks :D

Tue Jan 27 2015 at 4:37:10 PM u驴ytkownik Manish Goregaokar <
[email protected]> napisa鲁:

RUST_LOG=debug:crate::mod::mod::mod for some random module or crate you
wish to see the log of

Reply to this email directly or view it on GitHub
https://github.com/rust-lang/cargo/issues/818#issuecomment-71667895.

Very far from ideal, but worked for me right now. I've used std::env::set_var("RUST_LOG", "trace"); at the beginning of my test

Was this page helpful?
0 / 5 - 0 ratings