Reputation: 141
Is it possible to write log messages from different processes(executables) into the same log file. With Boost.Log in C++ (Boost.Log)
Upvotes: 0
Views: 866
Reputation: 10614
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.
Upvotes: 1
Reputation: 69892
No, and you wouldn't want to.
You'd need interprocess file locking for a start, which means that every thread of every process that was trying to log would all synchronise on one interprocess mutex. Performance-wise you'd be better off writing your entire software stack in one thread in one process!
Probably the way to achieve what you want is to have one process dedicated to logging, and send the log messages to that process via a unix socket, named pipe, or message bus.
Be sure to use async I/O to send those messages if it's over a socket. unix socket IO is very quick so you may not need it there.
Upvotes: 0