rlg-test 0.0.11

Test utilities for downstream consumers of rlg. Capture log records emitted inside a test scope and assert on them with the `assert_logged!` macro.
Documentation

Install

[dev-dependencies]
rlg-test = "0.0.11"

Requires Rust 1.88.0 or newer (edition 2024).

Usage

use rlg::log::Log;
use rlg::log_level::LogLevel;
use rlg_test::{capture, LogExt, assert_logged};

#[test]
fn emits_auth_record() {
    let capture = capture();

    // Route the record into the capture handle instead of the engine.
    Log::info("user authenticated")
        .component("auth")
        .with("user_id", 42_u64)
        .log_to(&capture);

    assert_logged!(capture, level == LogLevel::INFO);
    assert_logged!(capture, contains "authenticated");
    assert_logged!(capture, component "auth");
    assert_logged!(capture, attribute "user_id" => 42_u64);
    assert_logged!(capture, len == 1);
}

Predicates

Form Predicate
level == LogLevel::INFO record at the given level exists
contains "needle" record description contains the substring
attribute "k" => v record's attribute equals the value
component "name" record's component equals the string
len == n exactly n records were captured

Each is also exposed as a free function (has_level, description_contains, attribute_eq, has_component) so you can compose them or use them outside the macro.

License

Dual-licensed under Apache 2.0 or MIT, at your option.