On 2012-10-10 09:50, Robert Keizer wrote:
I have a production service that prints some debug to stdout. I could make it print to stderr, but it really doesn't matter in this case.
Are you sure it doesn't matter? Read on...
I want to have some hope of if something goes wrong figuring out what did. Log files aren't really an option so I ran it in screen. Yes yes I could have made it network log to somewhere else, but again, not really an viable option in this case. Works great as the program dies and the output stops, leaving the last debug messages in the buffer of screen.
One of the classic C/UNIX lessons about stdout vs stderr is that the C library buffers stdout by default but not stderr, exactly for the reason that you want error messages to be flushed out right away, leaving nothing in the buffer. This is particularly important if the program dies in a way that prevents the usual exit processing, such as flushing buffers and closing file I/O.
So, issues with "screen" aside, you probably should either send your debug output to stderr, or set your stdout to unbuffered mode while debugging (or both).