Skip to content
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

quill flush policy: call flush() every X seconds #8

Closed
azuresigma opened this issue Apr 10, 2020 · 2 comments
Closed

quill flush policy: call flush() every X seconds #8

azuresigma opened this issue Apr 10, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@azuresigma
Copy link

I am very new to quill. I am not sure if this is an issue for quill.

If an application prints just 1 log message ("program starts"), will quill use '\n' or std::endl here?
Will the log be buffered for a long time if the application doesn't log any more messages?
Sometimes it is not obvious to see whether a program doesn't hit that line of code or the log message is buffered, which causes some debugging anxiety.

Probably it will be better if quill backend thread can have an option to flush every X seconds, this can minimize lost messages during an unexpected crash. quill backend will do some unnecessary work here, but the main app thread can avoid paying the cost of calling quill::flush(). So main app thread can be fast, without worrying too much about logging messages being buffered.

@odygrd
Copy link
Owner

odygrd commented Apr 11, 2020

For each logged message Quill is using \n. It won't use something like std::endl as that would force flush each message.

Currently Quill is letting the OS to buffer all messages and the backend worker thread will never force flush.

The logic for this is here and I also have a TODO here

So what basically happens is :

  1. Quill buffers a log message to the OS but never force flushes
  2. If there are no more messages to process the backend thread goes into sleep but it will never force flush. I didn't want to spam flush on all handlers unconditionally when there are no more messages to log as there might be no messages for a long time.
  3. The backend thread however will always force flush everything before the application terminates. This is only in the case the application terminates successfully, not if it crashes

I understand your issue while debugging a running application you want to watch the logs.

  1. I will add a flush_every option when there are no more messages to buffer here that will flush all active handlers

or

  1. If there are no more messages left to log and we already buffered some unflushed messages then flush before sleep()

I will probably go for option 2 as it doesn't have to force flush() when there are zero buffered messages

@odygrd odygrd added the enhancement New feature or request label Apr 11, 2020
@odygrd odygrd closed this as completed in 68098bb Apr 11, 2020
@azuresigma
Copy link
Author

Thank you for quick turn-around. This implementation is better than flush every X seconds. I was thinking flush every X seconds would be a quick implementation. But your code is well written to prepare for this kind of change. Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants