-
I'm wondering if the following approach is ok for waiting until a flush request on an async logger has been completed (this is in a situation where you guarantee there are no new messages coming in to be logged, otherwise may be waiting forever if queue is growing from new log requests): // construct
spdlog::init_thread_pool(16384U, 6U);
auto spdlog_tp = spdlog::thread_pool();
auto async_logger = spdlog::create_async<sinks::basic_file_sink_mt>("logger_name", ...);
// ... do things
// flush when guaranteed no new logs coming in
async_logger.flush();
while(spdlog_tp->queue_size() != 0) { std::this_thread::sleep_for(Milliseconds(5)); } |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
As long as you are using async_logger.flush();
- while(spdlog_tp->queue_size() != 0) { std::this_thread::sleep_for(Milliseconds(5)); }
+ spdlog::shutdown(); Because: In spdlog 1.9.2, spdlog/include/spdlog/details/thread_pool-inl.h Lines 55 to 86 in eb32206
spdlog/include/spdlog/async_logger-inl.h Lines 40 to 50 in eb32206
spdlog/include/spdlog/details/thread_pool-inl.h Lines 33 to 53 in eb32206
spdlog/include/spdlog/details/registry-inl.h Lines 253 to 256 in a1d9f50 That is, as long as |
Beta Was this translation helpful? Give feedback.
-
If you can guarantee that no other log messages will be added to the thread pool queue, you can wait for the flush with the original solution. |
Beta Was this translation helpful? Give feedback.
TO: #2084 (reply in thread)
If you can guarantee that no other log messages will be added to the thread pool queue, you can wait for the flush with the original solution.