[Question] Is there a way to dynamically adjust the log levels of spdlog during runtime?
chenyongquan2 opened this issue · comments
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.
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.
I use SIGUSR2 signal and do it