Skip to content

Commit

Permalink
Remove context
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Dec 28, 2024
1 parent 7cfe4fc commit 035efac
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 124 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ set(SPDLOG_HEADERS
"include/spdlog/details/mpmc_blocking_q.h"
"include/spdlog/details/null_mutex.h"
"include/spdlog/details/os.h"
"include/spdlog/details/context.h"
"include/spdlog/bin_to_hex.h"
"include/spdlog/sinks/android_sink.h"
"include/spdlog/sinks/base_sink.h"
Expand Down Expand Up @@ -192,8 +191,7 @@ set(SPDLOG_SRCS
"src/details/os_filesystem.cpp"
"src/details/log_msg.cpp"
"src/details/async_log_msg.cpp"
"src/details/context.cpp"
"src/sinks/base_sink.cpp"
"src/sinks/base_sink.cpp"
"src/sinks/basic_file_sink.cpp"
"src/sinks/rotating_file_sink.cpp"
"src/sinks/stdout_sinks.cpp"
Expand Down
58 changes: 0 additions & 58 deletions include/spdlog/details/context.h

This file was deleted.

5 changes: 0 additions & 5 deletions include/spdlog/spdlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
#include <string_view>

#include "./common.h"
#include "./details/context.h"
#include "./logger.h"

namespace spdlog {

SPDLOG_API void set_context(std::shared_ptr<details::context> context);
SPDLOG_API std::shared_ptr<details::context> context();
SPDLOG_API const std::shared_ptr<details::context> &context_ref();

// Create a logger with a templated sink type
// Example:
// spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
Expand Down
44 changes: 0 additions & 44 deletions src/details/context.cpp

This file was deleted.

21 changes: 7 additions & 14 deletions src/spdlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,20 @@

namespace spdlog {

static std::shared_ptr s_context =

#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
std::make_unique<details::context>(std::make_unique<logger>(std::string(), std::make_unique<sinks::stdout_color_sink_mt>()));
static std::shared_ptr<logger> s_logger = std::make_shared<logger>("global", std::make_shared<sinks::stdout_color_sink_mt>());
#else
std::make_unique<details::context>(); // empty context
static std::short_ptr<logger> s_logger = nullptr;
#endif

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

std::shared_ptr<details::context> context() { return s_context; }

const std::shared_ptr<details::context> &context_ref() { return s_context; }

std::shared_ptr<logger> global_logger() { return context_ref()->global_logger(); }
std::shared_ptr<logger> global_logger() { return s_logger; }

void set_global_logger(std::shared_ptr<logger> global_logger) { context()->set_logger(std::move(global_logger)); }
void set_global_logger(std::shared_ptr<logger> global_logger) { s_logger = std::move(global_logger); }

logger *global_logger_raw() noexcept {
auto *rv = context_ref()->global_logger_raw();
assert(rv != nullptr);
return rv;
return s_logger.get();
}

void set_formatter(std::unique_ptr<formatter> formatter) { global_logger()->set_formatter(std::move(formatter)); }
Expand All @@ -52,6 +45,6 @@ void flush_on(level level) { global_logger()->flush_on(level); }

void set_error_handler(void (*handler)(const std::string &msg)) { global_logger()->set_error_handler(handler); }

void shutdown() { s_context.reset(); }
void shutdown() { s_logger.reset(); }

} // namespace spdlog

0 comments on commit 035efac

Please sign in to comment.