简体   繁体   English

将Boost.Log与Boost.Asio服务一起使用

[英]Using Boost.Log together with Boost.Asio services

I have a server which uses boost.asio services. 我有一个使用boost.asio服务的服务器。 I use boost.log for logging with an asynchronous sink. 我使用boost.log来记录异步接收器。 The asio_io_service gets started within an own thread. asio_io_service在自己的线程中启动。 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. 服务器接受与async_accept的连接,并异步读取和发送消息。

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. 好的,相关的stackoverflow-问题给了我答案:)默认情况下禁用了auto_flush。 So this single line in the logger initialization was the solution: 所以记录器初始化中的这一行是解决方案:

sink->locked_backend()->auto_flush(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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