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

update Log Messages/Configure Logging sections #696

Open
Arteiii opened this issue Apr 29, 2024 · 1 comment · May be fixed by #697
Open

update Log Messages/Configure Logging sections #696

Arteiii opened this issue Apr 29, 2024 · 1 comment · May be fixed by #697

Comments

@Arteiii
Copy link

Arteiii commented Apr 29, 2024

there are instances of code that may have previously worked but are now outdated due to changes in the env_logger crate

https://rust-lang-nursery.github.io/rust-cookbook/development_tools/debugging/config_log.html#use-a-custom-environment-variable-to-set-up-logging

use std::env;
use env_logger::Builder;

fn main() {
    Builder::new()
        .parse(&env::var("MY_APP_LOG").unwrap_or_default()) // Deprecated method
        .init();

    log::info!("informational message");
    log::warn!("warning message");
    log::error!("this is an error {}", "message");
}

Fix

https://docs.rs/env_logger/latest/env_logger/struct.Builder.html#method.from_env

use env_logger::Builder;

let mut builder = Builder::from_env("MY_APP_LOG");
builder.init();

or

https://docs.rs/env_logger/latest/env_logger/struct.Builder.html#method.parse_env

use log::LevelFilter;
use env_logger::Builder;

let mut builder = Builder::new();

builder.filter_level(LevelFilter::Off);
builder.parse_env("MY_APP_LOG");
builder.init();
@Arteiii
Copy link
Author

Arteiii commented Apr 29, 2024

I am not sure for what reason the latest version is shown in the badges, but wouldn't it be better to show the version for which the sample code is intended?

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

Successfully merging a pull request may close this issue.

1 participant