Skip to content

Logging from tests appears not to work as described in the docs #186

Closed
@wykurz

Description

@wykurz

Calling the init() defined as:

    fn init() {
        let _ = env_logger::Builder::new().is_test(true).try_init();
    }

in my tests appears not to produce any log output:

RUST_LOG=debug cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.02s
     Running target/debug/deps/log_fail-ea6852f038016c7e

running 1 test
test tests::test1 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

However running env_logger::init() does seem to work:

#[cfg(test)]
mod tests {
    #[test]
    fn test1() {
	env_logger::init();
        debug!("hello!");
	info!("hello!");
	error!("hello!");
	assert!(true);
    }
}

RUST_LOG=debug cargo test
Finished test [unoptimized + debuginfo] target(s) in 0.01s
Running target/debug/deps/log_fail-ea6852f038016c7e

running 1 test
[2020-11-23T05:39:32Z DEBUG log_fail::tests] hello!
[2020-11-23T05:39:32Z INFO log_fail::tests] hello!
[2020-11-23T05:39:32Z ERROR log_fail::tests] hello!
test tests::test1 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

This is with env_logger 0.8.2 and log 0.4.11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions