Skip to content

Commit

Permalink
More fixes relating to removal of factory and registry and thread pool
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Nov 23, 2024
1 parent 20cd446 commit 8d96662
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 299 deletions.
4 changes: 0 additions & 4 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ if(NOT benchmark_FOUND)
FetchContent_MakeAvailable(googlebenchmark)
endif()

add_executable(bench bench.cpp)
spdlog_enable_warnings(bench)
target_link_libraries(bench PRIVATE spdlog::spdlog)

add_executable(async_bench async_bench.cpp)
target_link_libraries(async_bench PRIVATE spdlog::spdlog)

Expand Down
2 changes: 1 addition & 1 deletion bench/async_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// bench.cpp : spdlog benchmarks
//
#include "spdlog/spdlog.h"
#include "spdlog/async.h"
#include "spdlog/async_logger.h"
#include "spdlog/sinks/basic_file_sink.h"

#if defined(SPDLOG_USE_STD_FORMAT)
Expand Down
246 changes: 0 additions & 246 deletions bench/bench.cpp

This file was deleted.

15 changes: 2 additions & 13 deletions include/spdlog/async_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,11 @@
// destructing..

#include <spdlog/logger.h>
#include <spdlog/details/thread_pool.h>
#include "spdlog/async_overflow_policy.h"
#include "spdlog/details/thread_pool.h"

namespace spdlog {

// Async overflow policy - block by default.
enum class async_overflow_policy {
block, // Block until message can be enqueued
overrun_oldest, // Discard oldest message in the queue if full when trying to
// add new item.
discard_new // Discard new message if the queue is full when trying to add new item.
};

namespace details {
class thread_pool;
}

class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>,
public logger {
friend class details::thread_pool;
Expand Down
14 changes: 14 additions & 0 deletions include/spdlog/async_overflow_policy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace spdlog {
// Async overflow policy - block by default.
enum class async_overflow_policy {
block, // Block until message can be enqueued
overrun_oldest, // Discard oldest message in the queue if full when trying to
// add new item.
discard_new // Discard new message if the queue is full when trying to add new item.
};

}


1 change: 1 addition & 0 deletions include/spdlog/details/thread_pool-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cassert>
#include <spdlog/common.h>
#include "spdlog/async_logger.h"

namespace spdlog {
namespace details {
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/details/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <spdlog/details/log_msg_buffer.h>
#include <spdlog/details/mpmc_blocking_q.h>
#include <spdlog/details/os.h>
#include <spdlog/async_overflow_policy.h>

#include <functional>
#include <memory>
Expand All @@ -15,7 +16,6 @@
namespace spdlog {
class async_logger;

enum class async_overflow_policy;
namespace details {

using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
Expand Down
24 changes: 0 additions & 24 deletions include/spdlog/sinks/stdout_color_sinks-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,4 @@
#include <spdlog/logger.h>

namespace spdlog {

template <typename Factory>
SPDLOG_INLINE std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name,
color_mode mode) {
return Factory::template create<sinks::stdout_color_sink_mt>(logger_name, mode);
}

template <typename Factory>
SPDLOG_INLINE std::shared_ptr<logger> stdout_color_st(const std::string &logger_name,
color_mode mode) {
return Factory::template create<sinks::stdout_color_sink_st>(logger_name, mode);
}

template <typename Factory>
SPDLOG_INLINE std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name,
color_mode mode) {
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name, mode);
}

template <typename Factory>
SPDLOG_INLINE std::shared_ptr<logger> stderr_color_st(const std::string &logger_name,
color_mode mode) {
return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode);
}
} // namespace spdlog
4 changes: 2 additions & 2 deletions include/spdlog/spdlog-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <spdlog/common.h>
#include <spdlog/pattern_formatter.h>
#include <spdlog/sinks/stdout_color_sinks-inl.h>
#include <spdlog/sinks/stdout_color_sinks.h>

namespace spdlog {

Expand All @@ -19,7 +19,7 @@ using default_sink_t = sinks::stdout_color_sink_mt;
using default_sink_t = sinks::null_sink_mt;
#endif

SPDLOG_INLINE static auto s_logger = std::make_shared<logger>("", std::make_shared<default_sink_t>());
static auto s_logger = std::make_shared<logger>("", std::make_shared<default_sink_t>());

SPDLOG_INLINE void set_formatter(std::unique_ptr<spdlog::formatter> formatter) {
s_logger->set_formatter(std::move(formatter));
Expand Down
3 changes: 0 additions & 3 deletions include/spdlog/spdlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include <spdlog/common.h>
#include <spdlog/logger.h>
#include <spdlog/version.h>

#include <chrono>
#include <functional>
#include <memory>
#include <string>

Expand Down
Loading

0 comments on commit 8d96662

Please sign in to comment.