Is a static constructor to configure spdlog safe to use? #2362
Answered
by
Iravoo
CPickens42
asked this question in
Q&A
-
Hello, I'm using spdlog and I have this in my code (C++20): #include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
[[maybe_unused]] auto static_ctor = std::invoke([]() { /* NOLINT */
// see https://spdlog.docsforge.com/v1.x/0.faq/#switch-the-default-logger-to-stderr
spdlog::set_default_logger(spdlog::stderr_color_mt("some_arbitrary_name"));
spdlog::set_default_logger(spdlog::stderr_color_mt(""));
spdlog::set_pattern("%^[%Y-%m-%d %T.%F | %-8l]%$ %v");
return nullptr;
}); I'm unsure of the safety of this. Could I encounter a "static initialization fiasco"? If so, in which cases? This is done like this to avoid to repeat the configuration of spdlog in every tests, in every main and so on. |
Beta Was this translation helpful? Give feedback.
Answered by
Iravoo
May 16, 2022
Replies: 1 comment 2 replies
-
I'm interested in this as well. Maybe @tt4g has an idea? 🙂 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
CPickens42
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm interested in this as well. Maybe @tt4g has an idea? 🙂