79528530

Date: 2025-03-23 06:11:47
Score: 0.5
Natty:
Report link

Answered my own question: of course after trying to get it to work for an hour or two, just minutes after posting this question I got it working:

    #[test_log::test(tokio::test)]
    async fn test_dynamic_logging3() {
        debug!("This will be ignored");

        let debug_subscriber = tracing_subscriber::fmt::Subscriber
            ::builder()
            .with_max_level(tracing::Level::DEBUG)
            .with_test_writer()
            .finish();
        tracing::subscriber::with_default(debug_subscriber, || {
            debug!("This will be logged");
        });
        debug!("This will be ignored");
    }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Niels Reijers