16

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Shailesh Kumar
  • 6,457
  • 8
  • 35
  • 60

1 Answers1

13

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.

creativcoder
  • 439
  • 5
  • 8
Manishearth
  • 14,882
  • 8
  • 59
  • 76