I have an application that must log each transaction. Every log message is flushed because we need to have a record of what occurred leading up to a crash. My colleagues and I were curious about how to achieve the performance effects of buffering while guaranteeing that the log message had left the process.
What we came-up with is:
- make a FIFO that the application can write to, and
- redirect the contents of that FIFO to a regular file via
That is, what was ordinarily:
app --logfile logfile.txt
mkfifo logfifo cat logfifo &> logfile.txt & app --logfile logfifo
Are there any gotchas to this approach? It worked when we tested it, but we want to make absolutely sure that the messages will find their way to the redirect file even if the original application crashes.
(We don't have the source code to the application, so programming solutions are out of the question. Also, the application won't write to
stdout, so piping directly to a different command is out of the question. So
syslog is not a possibility.)
Update: I've added a bounty. The accepted answer will not involve
logger for the simple reason that
logger is not what I've asked about. As the original question states, I am only looking for gotchas in using a FIFO.