I'm playing with Boost.Log in boost 1.54.0 to see if it is a viable option for my application. In general, I don't have a problem with the buffering, so I'm not looking to turn on auto_flush or anything... but I noticed that messages that are logged before I call fork()
are duplicated, and I'm wondering if it's because they are buffered, the buffer gets duplicated when the process image is copied, and then both processes eventually write their buffer copies to the log file...
So basically, I'd like to just do a manual flush on the log, one time only, immediately before I call fork()
in order to be sure no messages are still sitting in memory. In other words, I'm looking for something akin to fflush()
, .flush()
, << flush
, etc. that I can use on a boost log.
I did try using << flush
with the log, but I still get the duplicated messages, so I'm not 100% sure whether it's flushing and the duplicates are caused by some other problem, or if it somehow silently ignores the << flush
...
Edit:
I was looking around and found that boost log is not fork-safe. So I should add that I am not trying to use the same log in parent and child processes. I have two forking scenarios - in one, the parent terminates immediately and child contineus (so that should be safe), and in the other, the child should open its own separate log file, so that should be safe also... but I'd need to figure out how to close a log file sink and then open a new one (on a different file). I suppose closing the sink may also be a way to force a flush...?