| Crates.io | testlog |
| lib.rs | testlog |
| version | 0.1.3 |
| created_at | 2025-06-05 18:42:29.902107+00 |
| updated_at | 2025-06-10 22:44:12.69742+00 |
| description | A tiny macro for test-only stderr logging that activates only for the current crate |
| homepage | |
| repository | https://github.com/jodavaho/testlog |
| max_upload_size | |
| id | 1702112 |
| size | 6,817 |
Yes, One macro
A micro-crate that provides test_log! – a macro that prints to stderr only when tests are running, and only for the crate where it's used.
You need to debug test failures. It's tempting to add print statements to the library you're testing. But, adding print statements of any kind pollute the logs of the consumers of your library. What you want is something in your library that only prints for your tests, and ideally is only shown on failure.
This does exactly what you want: debug output that only appears during testing of your crate, and since output from a test is captured on success, you only see the log when the test fails. Perfect!.
Add to Cargo.toml:
[dependencies]
testlog = "0.1.3"
Use in your code:
use testlog::test_log;
fn complex_function(data: &[i32]) -> Vec<i32> {
test_log!("Processing {} items", data.len());
let result: Vec<i32> = data.iter()
.map(|&x| {
test_log!("Processing item: {}", x);
x * 2
})
.collect();
test_log!("Result: {:?}", result);
result
}
#[test]
fn test_complex_function() {
let input = vec![1, 2, 3];
let output = complex_function(&input);
assert_eq!(output, vec![2, 4, 6]);
// Debug output appears here when running `cargo test`
}
The test_log! macro checks cfg!(test) at compile time:
eprintln!(...), even still, the output is captured on successful tests, so it doesn't pollute.if false should be compiled out in release builds.That's it