Open SpyrosRoum opened 3 years ago
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()?;
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.
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 levelI'd be happy to help implement this. I am thinking the api would look something like
Logger::try_with_env("ENV_VARIABLE_NAME")
andLogger::try_with_env_or_str("ENV_VARIABLE_NAME", "info")