Keeping 'almost complete' logs even when system crashes
We have a c++ application (console) that runs on windows and unix. This application used output files to output verbose log files of system calls/prints/etc. The prblem is, that in certain occasion we might get signal 11/2 after new features are added.
Now whenever, that happenes, we do not get 'almost complete' information from log files to track down the origin of the bug/problem since the output files are no开发者_JAVA技巧t closed properly when signal 11 occurs. (it's only partial or zero sized)
We considered adding a flush command after every fprintf line print. Q :
- Is that considered a good practive ?
- does fflush works well on windows platfrom ?
- any thoughts/other methods to keep log files while system might crash unexpectedly ?
You need to send the log data not to the file, but to some external logging application which you can create in 30 minutes. Sending of output is possible via socket or via pipes or using SendMessage() Windows API ( if you target Windows ).
精彩评论