Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : how to use debug!(); ? #426

Open
stephan57160 opened this issue Jun 1, 2022 · 4 comments
Open

Question : how to use debug!(); ? #426

stephan57160 opened this issue Jun 1, 2022 · 4 comments
Labels

Comments

@stephan57160
Copy link
Contributor

I'm currently trying to play with flapigen internals, let's say, for some experiment.

I'm sure it's a rookie question, but how to use debug!() and mainly, how to see its output ?
Is there anything we have to initialise ?
I suppose there is something to add in my library's build.rs, right ?

@stephan57160
Copy link
Contributor Author

I mean ...
I saw a couple of debug!() in flapigen code itself.
How to use this ?
Is there any 'debug' log file ?

@Dushistov
Copy link
Owner

There are no something special. It is the same old log crate as everywhere.
You need register your logging implementation (for example env_logger )
in start of main and force it to output.

For example in cpp_tests:

env_logger::init();

So you need to run build with RUST_LOG=debug to see debug output, details you can find in env_logger documentation.
There are only one specific thing for build scripts, you get build script stdout/stderr in case of error,
so if all OK, then RUST_LOG=debug cargo build prints nothing, even you have thounds of debug!,
to see stdout/stderr you need RUST_LOG=debug cargo build -vv

@stephan57160
Copy link
Contributor Author

stephan57160 commented Jun 2, 2022

OK. Thx. Found it.

For those who will read this, in my build.rs:

fn main() {
    env_logger::init();
    debug!("Stephan's log sample");
    debug!("Stephan's log sample"); // twice !
    debug!("Another log exmple");

    let profile = std::env::var("PROFILE").unwrap();

With a

cargo clean
export RUST_LOG=debug ; cargo build

nothing happens on stdout.

But one can find the logs in target/debug/build/MyLibrary-xxx/stderr:

DEBUG:<unknown>: Stephan's log sample
DEBUG:<unknown>: Stephan's log sample
DEBUG:<unknown>: Another log exmple
...

Note
Do not forget to clean, else, build.rs is not executed if previous build is successful.

@Dushistov
Copy link
Owner

nothing happens on stdout.

As I wrote before you need "-vv" to see stdout of build script.

Do not forget to clean,

this is overkill, you need just touch path/to/build.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants