I ran the following code with two processes. In the output, there is only one entry. I get a different rank every time. Seems like each process overwrites the file. How can I make all processes to log a message without overwriting?
Expected result (order might be different):
0
1
Actual result:
0 // and sometimes 1
Code:
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/mpi.hpp>
int main()
{
boost::mpi::environment env;
boost::mpi::communicator world;
boost::log::add_file_log("sample.log");
BOOST_LOG_TRIVIAL(info) << world.rank();
return 0;
}
Boost log doesn't have such mechanism, but you can use separate process for logging data in the same file and provide access to this process outside. To achieve this approach you can use boost sockets or syslog backend