From 6651a48c4db192caee3c3bba521b3bcd6141f4f9 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 8 May 2019 17:50:23 +0300 Subject: [PATCH] wip --- include/spdlog/impl/base_sink.cpp | 54 +++++++++++++++++++++++++++++ include/spdlog/impl/thread_pool.cpp | 2 -- include/spdlog/sinks/base_sink.h | 45 ++++++------------------ 3 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 include/spdlog/impl/base_sink.cpp diff --git a/include/spdlog/impl/base_sink.cpp b/include/spdlog/impl/base_sink.cpp new file mode 100644 index 00000000..13b16ab2 --- /dev/null +++ b/include/spdlog/impl/base_sink.cpp @@ -0,0 +1,54 @@ +#ifdef SPDLOG_STATIC_LIB +#include "spdlog/sinks/base_sink.h" + +#include "spdlog/details/null_mutex.h" +#include +template class spdlog::sinks::base_sink; +template class spdlog::sinks::base_sink; +#endif + +#include "spdlog/common.h" +#include "spdlog/details/pattern_formatter.h" + +template +void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) +{ + std::lock_guard lock(mutex_); + sink_it_(msg); +} + +template +void SPDLOG_INLINE spdlog::sinks::base_sink::flush() +{ + std::lock_guard lock(mutex_); + flush_(); +} + +template +void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) +{ + std::lock_guard lock(mutex_); + set_pattern_(pattern); +} + +template +void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) +{ + std::lock_guard lock(mutex_); + set_formatter_(std::move(sink_formatter)); +} + +template +void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) +{ + set_formatter_(details::make_unique(pattern)); +} + +template +void SPDLOG_INLINE spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) +{ + formatter_ = std::move(sink_formatter); +} + + + diff --git a/include/spdlog/impl/thread_pool.cpp b/include/spdlog/impl/thread_pool.cpp index e97c30a5..fa8f961d 100644 --- a/include/spdlog/impl/thread_pool.cpp +++ b/include/spdlog/impl/thread_pool.cpp @@ -11,8 +11,6 @@ template class spdlog::details::mpmc_blocking_queue; SPDLOG_INLINE spdlog::details::thread_pool::thread_pool(size_t q_max_items, size_t threads_n) : q_(q_max_items) { - // std::cout << "thread_pool() q_size_bytes: " << q_size_bytes << - // "\tthreads_n: " << threads_n << std::endl; if (threads_n == 0 || threads_n > 1000) { throw spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid " diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 22595182..2ed1730a 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -13,7 +13,6 @@ #include "spdlog/common.h" #include "spdlog/details/log_msg.h" -#include "spdlog/formatter.h" #include "spdlog/sinks/sink.h" namespace spdlog { @@ -25,45 +24,21 @@ public: base_sink() = default; base_sink(const base_sink &) = delete; base_sink &operator=(const base_sink &) = delete; - - void log(const details::log_msg &msg) final - { - std::lock_guard lock(mutex_); - sink_it_(msg); - } - - void flush() final - { - std::lock_guard lock(mutex_); - flush_(); - } - - void set_pattern(const std::string &pattern) final - { - std::lock_guard lock(mutex_); - set_pattern_(pattern); - } - - void set_formatter(std::unique_ptr sink_formatter) final - { - std::lock_guard lock(mutex_); - set_formatter_(std::move(sink_formatter)); - } + void log(const details::log_msg &msg) final; + void flush() final;void set_pattern(const std::string &pattern) final; + void set_formatter(std::unique_ptr sink_formatter) final; protected: virtual void sink_it_(const details::log_msg &msg) = 0; virtual void flush_() = 0; - - virtual void set_pattern_(const std::string &pattern) - { - set_formatter_(details::make_unique(pattern)); - } - - virtual void set_formatter_(std::unique_ptr sink_formatter) - { - formatter_ = std::move(sink_formatter); - } + virtual void set_pattern_(const std::string &pattern); + virtual void set_formatter_(std::unique_ptr sink_formatter); Mutex mutex_; }; } // namespace sinks } // namespace spdlog + + +#ifndef SPDLOG_STATIC_LIB +#include "spdlog/impl/base_sink.cpp" +#endif \ No newline at end of file