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

buffered asynchronous logging #214

Open
iamshastry opened this issue May 8, 2022 · 3 comments
Open

buffered asynchronous logging #214

iamshastry opened this issue May 8, 2022 · 3 comments
Labels

Comments

@iamshastry
Copy link

is it possible to implement a buffer that accumulates logs and then writes to file ( either after N number of logs accumulated OR after certain elapse of timer ) using a thread asynchronously ? Could you please provide some insights on how / where in the code can this be achieved?

@SergiusTheBest
Copy link
Owner

Of course it's possible. But you have to understand what and why you're doing.

Here are some points to consider:

  • completely removing file operations from the Performance sample makes the code about 2 times faster (on the ordinary PC)
  • accumulated logs will be lost in case of an application crash
  • some platforms may have no threads

The best way is to make Record copyable and to create an asynchronous appender-wrapper that will accumulate records and send them to the real appender asynchronously:

class AsyncAppender : public IAppender
{
public:
    AsyncAppender(IAppender* realAppender);

Probably easier but not so versatile approach is to create AsyncFile and use it instead of File in RollingFileAppender.

@Smurf-IV
Copy link

Just my 2Cents:
How about taking the first part of the title: Buffered

And adding that to the util::File as an optional parameter (of say 4k increments).
And then setting the buffer used by the wsopen handle if it is greater then 0 ?

@Smurf-IV
Copy link

Another few cents.
For the Asynch part:
How about just having the "write" part being sent to an async lambda ? (Like async writes in C# etc.) ?
This way, the rest of the code can stay as it is, (i.e. no need to make copy constructors etc), and only the "Slow disk / Ip transport etc) stuff is asynch in "Maybe" a fire and forget fashion ?

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

No branches or pull requests

3 participants