diff --git a/include/spdlog/details/context.h b/include/spdlog/details/context.h index ccf72e7f..80b437f1 100644 --- a/include/spdlog/details/context.h +++ b/include/spdlog/details/context.h @@ -23,8 +23,9 @@ class thread_pool; class SPDLOG_API context { public: - context(); - ~context(); + context() = default; + explicit context(std::unique_ptr global_logger); + ~context() = default; context(const context &) = delete; context &operator=(const context &) = delete; diff --git a/src/details/context.cpp b/src/details/context.cpp index a4137cd8..6b291f38 100644 --- a/src/details/context.cpp +++ b/src/details/context.cpp @@ -13,15 +13,10 @@ namespace spdlog { namespace details { -context::context() { -#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER - auto color_sink = std::make_shared(); - global_logger_ = std::make_shared(std::string(), std::move(color_sink)); -#endif // SPDLOG_DISABLE_GLOBAL_LOGGER +context::context(std::unique_ptr global_logger) { + global_logger_ = std::move(global_logger); } -context::~context() = default; - std::shared_ptr context::global_logger() { return global_logger_; } diff --git a/src/spdlog.cpp b/src/spdlog.cpp index 256c87cc..e5994bde 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -12,7 +12,12 @@ namespace spdlog { -static std::shared_ptr s_context = std::make_unique(); +#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER +static std::shared_ptr s_context = + std::make_unique(std::make_unique("", std::make_unique())); +#else +static std::shared_ptr s_context = std::make_unique(); +#endif void set_context(std::shared_ptr context) { s_context = std::move(context); }