logwise 0.5.1

an opinionated logging library for Rust
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
use logwise::{Level, context::Context, declare_logging_domain, perfwarn_begin_if};
use std::thread;
use std::time::Duration;
declare_logging_domain!();
#[test]
fn test_perfwarn_if_logs_when_slow() {
    Context::reset("test_perfwarn_if_slow".to_string());

    // Threshold is 10ms, operation takes 50ms
    let threshold = Duration::from_millis(10);
    let interval = perfwarn_begin_if!(threshold, "slow_operation");

    thread::sleep(Duration::from_millis(50));
    drop(interval);

    // We can't easily assert on logs with the current test setup without a custom logger,
    // but we can ensure it runs without panicking and manually inspect if needed.
    // For automated verification, we'd need a mock logger, but existing tests use InMemoryLogger.
}

#[test]
fn test_perfwarn_if_skips_when_fast() {
    Context::reset("test_perfwarn_if_fast".to_string());

    // Threshold is 100ms, operation takes 1ms
    let threshold = Duration::from_millis(100);
    let interval = perfwarn_begin_if!(threshold, "fast_operation");

    thread::sleep(Duration::from_millis(1));
    drop(interval);
}

#[test]
fn test_perfwarn_if_statistics() {
    Context::reset("test_perfwarn_if_stats".to_string());

    // Create a task to collect stats
    let ctx = Context::new_task(
        Some(Context::current()),
        "stats_task".to_string(),
        Level::Info,
        true,
    );
    ctx.set_current();

    // 1. Fast operation (should NOT be logged in stats)
    {
        let threshold = Duration::from_millis(100);
        let interval = perfwarn_begin_if!(threshold, "fast_stat");
        thread::sleep(Duration::from_millis(1));
        drop(interval);
    }

    // 2. Slow operation (SHOULD be logged in stats)
    {
        let threshold = Duration::from_millis(10);
        let interval = perfwarn_begin_if!(threshold, "slow_stat");
        thread::sleep(Duration::from_millis(50));
        drop(interval);
    }

    // Task drop will log stats. We expect "slow_stat" but not "fast_stat".
}