Skip to content

Commit

Permalink
Moved default logger ctor to spdlog.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Dec 6, 2024
1 parent 8abaa0b commit 79df003
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions include/spdlog/details/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class thread_pool;

class SPDLOG_API context {
public:
context();
~context();
context() = default;
explicit context(std::unique_ptr<logger> global_logger);
~context() = default;
context(const context &) = delete;
context &operator=(const context &) = delete;

Expand Down
9 changes: 2 additions & 7 deletions src/details/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
namespace spdlog {
namespace details {

context::context() {
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
auto color_sink = std::make_shared<sinks::stdout_color_sink_mt>();
global_logger_ = std::make_shared<logger>(std::string(), std::move(color_sink));
#endif // SPDLOG_DISABLE_GLOBAL_LOGGER
context::context(std::unique_ptr<logger> global_logger) {
global_logger_ = std::move(global_logger);
}

context::~context() = default;

std::shared_ptr<logger> context::global_logger() {
return global_logger_;
}
Expand Down
7 changes: 6 additions & 1 deletion src/spdlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

namespace spdlog {

static std::shared_ptr<details::context> s_context = std::make_unique<details::context>();
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
static std::shared_ptr s_context =
std::make_unique<details::context>(std::make_unique<logger>("", std::make_unique<sinks::stdout_color_sink_mt>()));
#else
static std::shared_ptr s_context = std::make_unique<details::context>();
#endif

void set_context(std::shared_ptr<details::context> context) { s_context = std::move(context); }

Expand Down

0 comments on commit 79df003

Please sign in to comment.