进行货物测试时如何设置日志记录级别? [英] How to set logging level while running cargo test?

查看:117
本文介绍了进行货物测试时如何设置日志记录级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在运行库的单元测试时更改日志记录级别.我正在使用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还不支持,但是欢迎您提交

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆