GithubHelp home page GithubHelp logo

Capture logs inside tests? about fern HOT 2 OPEN

daboross avatar daboross commented on August 28, 2024
Capture logs inside tests?

from fern.

Comments (2)

sourcefrog avatar sourcefrog commented on August 28, 2024

It seems something like this will work. If there's no simpler way could I suggest this be added to the examples?

fn install_test_logger() {
    // This'll fail if called twice; don't worry.
    let _ = fern::Dispatch::new()
        // ...
        .level(log::LevelFilter::Debug)
        .chain(fern::Output::call(|record| println!("{}", record.args())))
        .apply();
}```

from fern.

daboross avatar daboross commented on August 28, 2024

Thanks! I hadn't realized that the test framework's hook was per-thread rather than global. Makes sense now that I think about it, though.

Adding that as an example sounds like a good idea. It might also be worth adding to this note as well (or we could just remove the stdout from this example; it isn't really relevant):

fern/src/builders.rs

Lines 691 to 701 in 6666bd2

/// fern::Dispatch::new()
/// // format, etc.
/// .chain(std::io::stdout())
/// .chain(
/// fern::Dispatch::new()
/// .level(log::LevelFilter::Error)
/// .chain(fern::Panic),
/// )
/// # /*
/// .apply()?;
/// # */ .into_log();
.

from fern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.