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)
|
for(unsigned int i = 1; i <= howmany ; ++i)
|
||||||
my_logger.info() << "Hello logger: " << 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 = system_clock::now() - start;
|
||||||
auto delta_d = duration_cast<duration<double>> (delta).count();
|
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() << "Delta:" << format(delta_d);
|
||||||
cout_logger.info() << "Rate:" << format(howmany/delta_d) << "/sec";
|
cout_logger.info() << "Rate:" << format(s/delta_d) << "/sec";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
~async_sink();
|
~async_sink();
|
||||||
void add_sink(logger::sink_ptr sink);
|
void add_sink(logger::sink_ptr sink);
|
||||||
void remove_sink(logger::sink_ptr sink_ptr);
|
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
|
//Wait to remaining items (if any) in the queue to be written and shutdown
|
||||||
void shutdown(const std::chrono::milliseconds& timeout);
|
void shutdown(const std::chrono::milliseconds& timeout);
|
||||||
|
|
||||||
@ -82,20 +82,13 @@ inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
|
|||||||
if(!_active || !msg_size)
|
if(!_active || !msg_size)
|
||||||
return;
|
return;
|
||||||
//re allocate on the heap the (stack based) message
|
//re allocate on the heap the (stack based) message
|
||||||
auto new_msg = new details::log_msg();
|
auto new_msg = new details::log_msg(msg);
|
||||||
*new_msg = msg;
|
|
||||||
|
|
||||||
char *buf = new char[msg_size];
|
char *buf = new char[msg_size];
|
||||||
std::memcpy(buf, msg.msg_buf.first, msg_size);
|
std::memcpy(buf, msg.msg_buf.first, msg_size);
|
||||||
new_msg->msg_buf = bufpair_t(buf, msg_size);
|
new_msg->msg_buf = bufpair_t(buf, msg_size);
|
||||||
/*
|
// Create unique_ptr with custom deleter and push it
|
||||||
auto new_shared_msg = queue_type::item_type(new_msg, [](const details::log_msg* msg_to_delete)
|
queue_type::item_type new_shared_msg(new_msg, msg_deleter);
|
||||||
{
|
|
||||||
delete []msg_to_delete->msg_buf.first;
|
|
||||||
delete msg_to_delete;
|
|
||||||
});
|
|
||||||
* */
|
|
||||||
queue_type::item_type new_shared_msg(new_msg, msg_deleter);
|
|
||||||
_q.push(std::move(new_shared_msg));
|
_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());
|
_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)
|
inline void c11log::sinks::async_sink::shutdown(const std::chrono::milliseconds& timeout)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user