-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make async_logger::flush() synchronous and wait for the flush to comp… #3049
Conversation
7f9d03a
to
cbf2f32
Compare
It won’t help if the queue was created with discard flag and the flush message gets discarded.. |
cbf2f32
to
ac79056
Compare
I don't understand the problem. Could you clarify? I you mean that the flush signal gets discarded: if the async_msg containing a flush promise gets discard, the promise would be "broken" and then the future.get() call would get and broken promise exception, which would be passed into the error handler for the logger. |
Yes, and this means that again flush() won’t work as expected even after this fix. If queue is full, flush() fails without any indication(returns void). |
If queue is full, flush() will fail, but, there is indication: a std::promise destructed without calling set_value() will cause exception to be thrown. Here is an example:
So there would be indicatin through the global error handler. I do noticed the issue that flush() does not return anything. But changing this would change the interface and would break API compatibility, so it might need to go to v2.x. And since spdlog use exception and logger error handler for error propogation, I continue to use this pattern. As for queue-full-and-drop-message design, I think this is by design and not needed to change. And if we do need to change that, it would not be a easy task because the current design share thread pool and queue between multiple logger. |
By the way, I am seeing "Some checks were not successful" and "1 review requesting changes" but I don't understand what is requested to be changed. |
Ok, seems this is the best we can do without breaking the API. |
Thanks @walkerlala |
@walkerlala Can you check why msvc test fails here? |
Sure. I would check it as soon as possible. |
This patch make the async_logger::flush() interface a synchronous operation, similar to that of normal logger::flush(). The flush operation return only after it succeeds or fail. If failed, the error handler would be invoked with a exception message.
This patch also modify the minimum c++ stdandard to be c++14, to be able to use functions like std::make_unique().