进行货物测试时如何设置日志记录级别? [英] How to set logging level while running cargo test?
问题描述
我需要在运行库的单元测试时更改日志记录级别.我正在使用cargo test
命令来运行测试.
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.
推荐答案
Cargo doesn't support this yet, but you are welcome to file an issue for it.
RUST_LOG=debug cargo test
应该可以工作,您可以为单个命令设置环境变量,而不是为当前环境设置它们.
RUST_LOG=debug cargo test
should work, you can set environment variables for single commands instead of setting them for the current environment.
有关RUST_LOG
env变量的更多信息此处.
More info on the RUST_LOG
env variable here.
这篇关于进行货物测试时如何设置日志记录级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!