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

[Question][Bug] How come load_env_levels() overrides levels to default of info when SPDLOG_LEVEL env var doesn't exist? #1680

Closed
Tridacnid opened this issue Sep 24, 2020 · 5 comments
Labels

Comments

@Tridacnid
Copy link
Contributor

It looks like calling load_env_levels() when SPDLOG_LEVEL doesn't exist overwrites every registered logger's level to a default of "info". Additionally, when SPDLOG_LEVEL does exist but only specifies a couple logger's levels, the others have their levels overwritten to the default of info.

pseduo-code example:

// export SPDLOG_LEVEL=logger2=off

// create "logger1" and set level to trace
auto logger1{spdlog::stdout_color_mt("logger1");
logger1->set_level(trace);
spdlog::register_logger(logger1);

// create "logger2" and set level to debug
auto logger2{spdlog::stderr_color_mt("logger2");
logger2->set_level(debug);
spdlog::register_logger(logger2);

spdlog:;cfg::load_env_levels();

// logger2 is set to off level as expected, but logger1 is now set to info even though it wasn't specified in SPDLOG_LEVEL
// if SPDLOG_LEVEL doesn't exist in the environment, both logger1 and logger2 would be set to info

Is this by design? It's certainly annoying that a missing env var will reset the logger levels I have specified in my source code. I wouldn't expect a logger's level to change if it wasn't present in the env var.

As a side note, it looks like the argv processing suffers from this same behavior.

@gabime
Copy link
Owner

gabime commented Sep 25, 2020

It is not by design. This is indeed an annoying bug

@gabime gabime added the bug label Sep 25, 2020
@Tridacnid
Copy link
Contributor Author

I have a fix I'll try to submit as a patch this weekend for the empty env var + unit tests for that case.

Is the SPDLOG_LEVEL=logger2=off affecting logger1's level also a bug or is that intentional? I took a look and changing that might be more involved.

@gabime
Copy link
Owner

gabime commented Sep 25, 2020

I have a fix I'll try to submit as a patch this weekend

Don't bother. My fix is almost ready.

Is the SPDLOG_LEVEL=logger2=off affecting logger1's level also a bug or is that intentional?

Also a bug. Will be fixed as well.

gabime pushed a commit that referenced this issue Sep 26, 2020
@gabime gabime closed this as completed in 54a8259 Sep 26, 2020
gabime pushed a commit that referenced this issue Sep 26, 2020
gabime pushed a commit that referenced this issue Sep 26, 2020
gabime pushed a commit that referenced this issue Sep 26, 2020
gabime pushed a commit that referenced this issue Sep 26, 2020
@gabime
Copy link
Owner

gabime commented Sep 26, 2020

@Tridacnid Fixed. Please verify works for you as well

@Tridacnid
Copy link
Contributor Author

Ran some quick tests and everything looks like it's behaving nicely now, thanks!

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

No branches or pull requests

2 participants