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

Give the ability to specify what env variable to read the level specification from #84

Open
SpyrosRoum opened this issue Aug 9, 2021 · 2 comments

Comments

@SpyrosRoum
Copy link

Hello, I believe it would be a good idea to allow for custom env variables (maybe with RUST_LOG being the default).
This way I can use flexi_logger for more than one apps at a time and each one can have their own log level

I'd be happy to help implement this. I am thinking the api would look something like Logger::try_with_env("ENV_VARIABLE_NAME") and Logger::try_with_env_or_str("ENV_VARIABLE_NAME", "info")

@emabee
Copy link
Owner

emabee commented Aug 10, 2021

Hi Spyros,
I agree that the hard-coded treatment of RUST_LOG is questionable, but it's there since ever, to be compatible with env_logger.

The desired result can also be achieved with:

    use flexi_logger::Logger;

    let _logger = Logger::try_with_str(
        std::env::var("MY_ENV_VAR")
            .or(std::env::var("RUST_LOG"))
            .as_deref()
            .unwrap_or("info"),
    )?
    .start()?;

@SpyrosRoum
Copy link
Author

I wasn't aware that env_logger has the same limitation.
Doing it the way you suggest was my backup, I was just hoping to get this abstracted in your library, especially since I assume it is a common thing people would like to do.

This might be starting to get ugly but you could introduce new methods like try_with_custom_env, this way doesn't break backwards compatibility either.

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

2 participants