spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

Blocking flush on async_logger

Open mateuszzz88 opened this issue 4 years ago • 4 comments

spdlog::async_logger::flush() is non-blocking operation. Flush is scheduled for later. I would like to have blocking variant that will wait untill everything that was scheduled for logging untill now is flushed by all sinks. My usecase is that I want to be be sure that everything I wanted to log is safe on disk and can be passed for further processing outside program. Frankly I don't see value in flush operation that doesn't flush NOW and only promises it will be done later. It will be done later anyway, at shutdown at latest.

mateuszzz88 avatar Oct 07 '20 10:10 mateuszzz88

Try call spdlog::shutdown().

tt4g avatar Oct 07 '20 10:10 tt4g

Further logging is then impossible: C++ exception with description "async log: thread pool doesn't exist anymore" thrown in the test body.

mateuszzz88 avatar Oct 07 '20 11:10 mateuszzz88

Yes. spdlog::shutdown() should be called just before the application exit.

tt4g avatar Oct 07 '20 12:10 tt4g

I realize this is feature request. Best API (IMO) would be for flush to return std::future. But separate flush methods are ok too.

mateuszzz88 avatar Oct 08 '20 09:10 mateuszzz88