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

Terminal output not working when things are initialized from a crate #81

Closed
parazyd opened this issue Sep 23, 2021 · 5 comments
Closed

Comments

@parazyd
Copy link

parazyd commented Sep 23, 2021

I'm trying to have a general log initializing function that I can share
between my binaries. However, it seems that terminal output does
not happen in this case, and I'm not sure why. Any clues on how I
can get this working so I get the logging both on the terminal and
in my logfile? Suffice to say, it works if I use the lib.rs code in my
binary directly, and not as an abstracted function in a crate.

lib.rs

use simplelog::*

pub fn init_logging(verbose: bool, log_path: &str) -> Result<(), log::SetLoggerError> {
    let debug_level = if verbose { LevelFilter::Debug } else {LevelFilter::Off };
    let logger_config = ConfigBuilder::new().set_time_format_str("%T%6.f").build();

    Ok(CombinedLogger::init(vec![
        SimpleLogger::new(debug_level, logger_config),
        WriteLogger::new(
            LevelFilter::Debug,
            Config::default(),
            std::fs::File::create(log_path).unwrap(),
        ),
    ])?)
}

bin/logme.rs

use log::debug;
use my_crate::init_logging;

fn main() -> Result<(), log::SetLoggerError> {
    init_logging(true, "/tmp/mylog.txt")?;
    debug!("I see this in my file but not on my terminal");
    Ok(())
}
@m-lima
Copy link

m-lima commented Sep 27, 2021

To expand more on the problem, which I believe to be the same problem, no terminal output logging is working in general.
To confirm this, I ran the README.md example and got no terminal output. Also, none of the example binaries in the examples folder were able to output to the terminal, but file logging did work

@m-lima
Copy link

m-lima commented Sep 27, 2021

So simplelog = "=0.10.0" works with terminal output, but simplelog = "0.10.1" does not.
Maybe a regression in ce44265?

@Drakulix
Copy link
Owner

Likely related to #82, can you test the current master branch? I will likely release 0.10.2 on crates.io later today.

@m-lima
Copy link

m-lima commented Sep 27, 2021

Likely related to #82, can you test the current master branch? I will likely release 0.10.2 on crates.io later today.

Master works with my previous tests 👍

@Drakulix
Copy link
Owner

0.10.2 is released and 0.10.1 yanked.

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

No branches or pull requests

3 participants