#log-messages #log #logging #test

log_tester

Test for log messages produced by the log crate

3 releases

0.1.2 Aug 3, 2024
0.1.1 Jul 31, 2024
0.1.0 Jul 31, 2024

#288 in Debugging

Download history 119/week @ 2024-07-25 246/week @ 2024-08-01 32/week @ 2024-08-08 16/week @ 2024-08-15 3/week @ 2024-08-22 10/week @ 2024-08-29 1/week @ 2024-09-05 26/week @ 2024-09-12 27/week @ 2024-09-19 32/week @ 2024-09-26 3/week @ 2024-10-03

89 downloads per month

GPL-3.0-only

16KB
158 lines

log_tester

crates.io Documentation License: GNU GPLv3

log_tester is a crate that takes care of capturing log messages produced by the log crate during test, and then perform checks on them.

Warnings

This crate is made to capture all logs, including in multithreaded case. Hence, it does not work well with cargo test, the logs from all test will be captured.

It is better to use cargo nextest instead.

Using cargo test will not fail but additional logs will be captured. In that way the test may not be right.

Usage

This crate is intend to be used in conjunction with the log crate. And only during test.

[dependencies]
log = "0.4"

[dev-dependencies]
log_tester = "0.1"
use log_tester::LogTester;
use log::Level;

#[test]
fn test_log() {
    LogTester::start();
    log::info!("Hello, world!");

    assert!(LogTester::contains(Level::Info, "Hello, world!"))
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Authors

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Dependencies

~87KB