mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-27 07:14:12 +08:00
wip
This commit is contained in:
parent
c031ae2aab
commit
6651a48c4d
54
include/spdlog/impl/base_sink.cpp
Normal file
54
include/spdlog/impl/base_sink.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#ifdef SPDLOG_STATIC_LIB
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include <mutex>
|
||||
template class spdlog::sinks::base_sink<std::mutex>;
|
||||
template class spdlog::sinks::base_sink<spdlog::details::null_mutex>;
|
||||
#endif
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/pattern_formatter.h"
|
||||
|
||||
template <typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
sink_it_(msg);
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::flush()
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
flush_();
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_pattern_(pattern);
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_formatter_(std::move(sink_formatter));
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
||||
{
|
||||
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,8 +11,6 @@ template class spdlog::details::mpmc_blocking_queue<spdlog::details::async_msg>;
|
||||
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 "
|
||||
|
@ -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<Mutex> lock(mutex_);
|
||||
sink_it_(msg);
|
||||
}
|
||||
|
||||
void flush() final
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
flush_();
|
||||
}
|
||||
|
||||
void set_pattern(const std::string &pattern) final
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_pattern_(pattern);
|
||||
}
|
||||
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final
|
||||
{
|
||||
std::lock_guard<Mutex> 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<spdlog::formatter> 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<spdlog::pattern_formatter>(pattern));
|
||||
}
|
||||
|
||||
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
virtual void set_pattern_(const std::string &pattern);
|
||||
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
|
||||
Mutex mutex_;
|
||||
};
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
|
||||
#ifndef SPDLOG_STATIC_LIB
|
||||
#include "spdlog/impl/base_sink.cpp"
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user