mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
async_sink
This commit is contained in:
parent
28e1c65963
commit
133ce994d1
@ -35,13 +35,14 @@ int main(int argc, char* argv[])
|
||||
for(unsigned int i = 1; i <= howmany ; ++i)
|
||||
my_logger.info() << "Hello logger: " << i;
|
||||
|
||||
as->shutdown(milliseconds(500));
|
||||
//as->shutdown(milliseconds(500));
|
||||
auto s = howmany - as->q().size();
|
||||
auto delta = system_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>> (delta).count();
|
||||
|
||||
cout_logger.info() << "Total:" << format(howmany);
|
||||
cout_logger.info() << "Total:" << format(s);
|
||||
cout_logger.info() << "Delta:" << format(delta_d);
|
||||
cout_logger.info() << "Rate:" << format(howmany/delta_d) << "/sec";
|
||||
cout_logger.info() << "Rate:" << format(s/delta_d) << "/sec";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
~async_sink();
|
||||
void add_sink(logger::sink_ptr sink);
|
||||
void remove_sink(logger::sink_ptr sink_ptr);
|
||||
|
||||
queue_type& q();
|
||||
//Wait to remaining items (if any) in the queue to be written and shutdown
|
||||
void shutdown(const std::chrono::milliseconds& timeout);
|
||||
|
||||
@ -82,19 +82,12 @@ inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
|
||||
if(!_active || !msg_size)
|
||||
return;
|
||||
//re allocate on the heap the (stack based) message
|
||||
auto new_msg = new details::log_msg();
|
||||
*new_msg = msg;
|
||||
auto new_msg = new details::log_msg(msg);
|
||||
|
||||
char *buf = new char[msg_size];
|
||||
std::memcpy(buf, msg.msg_buf.first, msg_size);
|
||||
new_msg->msg_buf = bufpair_t(buf, msg_size);
|
||||
/*
|
||||
auto new_shared_msg = queue_type::item_type(new_msg, [](const details::log_msg* msg_to_delete)
|
||||
{
|
||||
delete []msg_to_delete->msg_buf.first;
|
||||
delete msg_to_delete;
|
||||
});
|
||||
* */
|
||||
// Create unique_ptr with custom deleter and push it
|
||||
queue_type::item_type new_shared_msg(new_msg, msg_deleter);
|
||||
_q.push(std::move(new_shared_msg));
|
||||
}
|
||||
@ -127,6 +120,11 @@ inline void c11log::sinks::async_sink::remove_sink(logger::sink_ptr sink_ptr)
|
||||
_sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink_ptr), _sinks.end());
|
||||
}
|
||||
|
||||
inline c11log::sinks::async_sink::queue_type& c11log::sinks::async_sink::q()
|
||||
{
|
||||
return _q;
|
||||
}
|
||||
|
||||
|
||||
inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user