Boost日志 - 一个日志文件的不同进程?

时间:2016-04-04 14:52:08

标签: c++ logging boost

是否可以将来自不同进程(可执行文件)的日志消息写入同一日志文件中。使用Boost.Log C ++(Boost.Log

2 个答案:

答案 0 :(得分:1)

This is not directly supported. Boost.Log performs no inter-process synchronization and it doesn't expect other processes messing with log files.

It is possible to implement an inter-process logging scheme, where multiple processes send log records to the one common process that is actually writing the log file. You can do that with a syslog backend or a stream backend with a socket-based stream. Of course, implementing a custom sink backend is also a possibility.

答案 1 :(得分:0)

不,你不会想要。

您需要启动进程间文件锁定,这意味着尝试记录的每个进程的每个线程都将在一个进程间互斥锁上同步。在性能方面,您最好在一个流程中在一个流程中编写整个软件堆栈!

实现所需内容的方法可能是让一个进程专用于日志记录,并通过unix套接字,命名管道或消息总线将日志消息发送到该进程。

确保使用异步I / O发送这些消息(如果它在套接字上)。 unix socket IO非常快,所以你可能不需要它。