diff --git a/example/example.cpp b/example/example.cpp index df72c907a73984907157a06e12c6c21a1248c795..e9e57f8327eaab465ca43f19372bf69b3694de68 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) //auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, 0); - auto as = std::make_shared<sinks::async_sink>(howmany); + auto as = std::make_shared<sinks::async_sink>(1000); as->add_sink(sinks::null_sink::get()); logger my_logger ("my_logger", as); @@ -33,7 +33,7 @@ int main(int argc, char* argv[]) for(unsigned int i = 0; i < howmany ; i++) my_logger.info() << "Hello logger"; - + as->shutdown(milliseconds(5000)); auto delta = system_clock::now() - start; auto delta_d = duration_cast<duration<double>> (delta).count(); diff --git a/include/c11log/sinks/async_sink.h b/include/c11log/sinks/async_sink.h index f84e845ea967bd7d750ccf7e1a9069623284c798..61f932d09ec6b21019027ecfd205a8726b7ea0f7 100644 --- a/include/c11log/sinks/async_sink.h +++ b/include/c11log/sinks/async_sink.h @@ -68,8 +68,8 @@ inline c11log::sinks::async_sink::~async_sink() } inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg) { - auto msg_size = msg.msg_buf.second; - if(!msg_size) + auto msg_size = msg.msg_buf.second; + if(!_active || !msg_size) return; //re allocate on the heap the (stack based) message auto new_msg = new details::log_msg();