简体   繁体   中英

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, eg 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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM