Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Boost.Log together with Boost.Asio services

I have a server which uses boost.asio services. I use boost.log for logging with an asynchronous sink. The asio_io_service gets started within an own thread. The logger gets initialized in the main thread before starting the server. The server accepts connections with async_accept and reads and sends messages also asynchronously.

Now I have the problem, that the logger logs only messages when the server is doing something, e.g. receiving messages. When I log a message after logger initialization and before starting the server I can see this log message only after the first message was received by the server. But I want to log messages even when no server actions happen. Have you an idea what the problem is and how I can solve it?

like image 674
Paul Avatar asked Apr 17 '26 12:04

Paul


1 Answers

Okay, the related stackoverflow-questions gave me the answer :) It was the by default disabled auto_flush. So this single line in the logger initialization was the solution:

sink->locked_backend()->auto_flush(true);
like image 85
Paul Avatar answered Apr 19 '26 02:04

Paul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!