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] Is there a way to dynamically adjust the log levels of spdlog during runtime? #3102

Open
chenyongquan2 opened this issue May 30, 2024 · 2 comments

Comments

@chenyongquan2
Copy link

chenyongquan2 commented May 30, 2024

I had asked a question earlier:
#3099

But I still have some questions:
During the execution of the program, I modify the value of the environment variable SPDLOG_LEVEL, and I also have a thread that constantly executes spdlog::cfg::load_env_levels(); Can I use the above method to change the log_level of my spdlog at runtime? Or are there other ways to dynamically adjust the output log_level value during program runtime?

In my current project, I expect to dynamically enable the output of trace-level logs only in some exceptional cases (this log printing has a very high frequency, so I hope to print it only when I need it, in order to avoid the situation of overly large logs), while in normal cases, I expect to only output info-level logs.

@tt4g
Copy link
Contributor

tt4g commented May 30, 2024

Although spdlog::cfg::load_env_levels() can be called multiple times, operations that update and read environment variables at runtime are not guaranteed to be thread-safe by the C language specification.
If a bug occurs, it is not the responsibility of spdlog.
See: https://stackoverflow.com/a/50479023

Other ways can be implemented freely in your project.
spdlog does not restrict you from calling spdlog::logger::set_level() to change the log level.

@smohanty92
Copy link

I use SIGUSR2 signal and do it

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