Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set logging level while running cargo test? [duplicate]

I need to change the logging level while running the unit tests for a library. I am using the cargo test command to run the tests.

Is there any way to specify the logging level on the command line? From the documentation of the log crate, it seems like I need to define an environment variable separately. That may not be convenient as I would like to change the logging level to debug only when a test case fails.

like image 629
Shailesh Kumar Avatar asked Nov 07 '14 15:11

Shailesh Kumar


People also ask

How do I increase my log level?

Server Configuration File You can change the log level through a Windows Registry file or a Linux configuration file. Add the logLevel string, and set the desired value (e.g., DEBUG). Click OK to save.

Does cargo run tests in parallel?

The default behavior of the binary produced by cargo test is to run all the tests in parallel and capture output generated during test runs, preventing the output from being displayed and making it easier to read the output related to the test results.

Does cargo build run tests?

cargo test runs additional checks as well. It will compile any examples you've included to ensure they are still compiles. It also run documentation tests to ensure your code samples from documentation comments compiles.


1 Answers

Cargo doesn't support this yet, but you are welcome to file an issue for it.

RUST_LOG=debug cargo test should work, you can set environment variables for single commands instead of setting them for the current environment.

More info on the RUST_LOG env variable here.

like image 171
Manishearth Avatar answered Sep 20 '22 03:09

Manishearth