mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
async using lockfree queue and bug fixes regarding usage of cppformat
This commit is contained in:
@@ -25,8 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include "../sinks/async_sink.h"
|
||||
#include "./async_log_helper.h"
|
||||
|
||||
//
|
||||
// Async Logger implementation
|
||||
@@ -38,11 +37,11 @@ template<class It>
|
||||
inline spdlog::async_logger::async_logger(const std::string& logger_name, const It& begin, const It& end, size_t queue_size, const log_clock::duration& shutdown_duration) :
|
||||
logger(logger_name, begin, end),
|
||||
_shutdown_duration(shutdown_duration),
|
||||
_as(std::unique_ptr<sinks::async_sink>(new sinks::async_sink(queue_size)))
|
||||
_async_log_helper(new details::async_log_helper(queue_size))
|
||||
{
|
||||
_as->set_formatter(_formatter);
|
||||
_async_log_helper->set_formatter(_formatter);
|
||||
for (auto &s : _sinks)
|
||||
_as->add_sink(s);
|
||||
_async_log_helper->add_sink(s);
|
||||
}
|
||||
|
||||
inline spdlog::async_logger::async_logger(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const log_clock::duration& shutdown_duration) :
|
||||
@@ -52,21 +51,16 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name, sink_p
|
||||
async_logger(logger_name, { single_sink }, queue_size, shutdown_duration) {}
|
||||
|
||||
|
||||
inline void spdlog::async_logger::_log_msg(details::log_msg& msg)
|
||||
{
|
||||
_as->log(msg);
|
||||
}
|
||||
|
||||
inline void spdlog::async_logger::_set_formatter(spdlog::formatter_ptr msg_formatter)
|
||||
{
|
||||
_formatter = msg_formatter;
|
||||
_as->set_formatter(_formatter);
|
||||
_async_log_helper->set_formatter(_formatter);
|
||||
}
|
||||
|
||||
inline void spdlog::async_logger::_set_pattern(const std::string& pattern)
|
||||
{
|
||||
_formatter = std::make_shared<pattern_formatter>(pattern);
|
||||
_as->set_formatter(_formatter);
|
||||
_async_log_helper->set_formatter(_formatter);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,5 +68,10 @@ inline void spdlog::async_logger::_set_pattern(const std::string& pattern)
|
||||
inline void spdlog::async_logger::_stop()
|
||||
{
|
||||
set_level(level::OFF);
|
||||
_as->shutdown(_shutdown_duration);
|
||||
_async_log_helper->shutdown(_shutdown_duration);
|
||||
}
|
||||
|
||||
inline void spdlog::async_logger::_log_msg(details::log_msg& msg)
|
||||
{
|
||||
_async_log_helper->log(msg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user