|
|
|
@ -13,6 +13,8 @@
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE spdlog::async_logger::async_logger(
|
|
|
|
|
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
|
|
|
|
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
|
|
|
|
@ -88,3 +90,35 @@ SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::s
|
|
|
|
|
cloned->name_ = std::move(new_name);
|
|
|
|
|
return cloned;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE bool spdlog::async_logger::sync(int intervalMs, int timeoutMs)
|
|
|
|
|
{
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
|
|
auto tp=thread_pool_.lock();
|
|
|
|
|
assert(tp);
|
|
|
|
|
|
|
|
|
|
if (tp->queue_size()==0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
auto start=steady_clock::now();
|
|
|
|
|
bool synced=false;
|
|
|
|
|
bool indef=(timeoutMs<=0);
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (!indef && intervalMs>timeoutMs)
|
|
|
|
|
intervalMs=timeoutMs;
|
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(milliseconds(intervalMs));
|
|
|
|
|
synced=(tp->queue_size()==0);
|
|
|
|
|
|
|
|
|
|
if (!indef)
|
|
|
|
|
{
|
|
|
|
|
auto now=steady_clock::now();
|
|
|
|
|
auto passedMs=duration_cast<milliseconds>(now-start);
|
|
|
|
|
start=now;
|
|
|
|
|
timeoutMs-=passedMs.count();
|
|
|
|
|
}
|
|
|
|
|
} while ((!indef && timeoutMs>0 || indef) && !synced);
|
|
|
|
|
return synced;
|
|
|
|
|
}
|
|
|
|
|