I'd like to:
- redirect stdout/stderr
- to an in-memory buffer, rather than to disk
- while leaving stdout/err running as normal
I know how to use dup2 and freopen to:
- redirect stdout/err to a file of my choosing
- while leaving stdout/err running as normal
...but I'm not sure about item 2?
REASON: I want to post-process the data going to stdout/err (that's coming from 3rd party code), and then send it to a webserver - while leaving the application running as normal.
WHY? ... because right now when our app runs we're seeing critical data go to stdout (and err) from 3rd party code, and it's a PITA getting users to try and mess around with local logfiles. I'd rather capture "the last N bytes" into a ring buffer, post-process it, and then - iff there's a problem that the user reports - send that to server.
WHY AVOID FILES? ... because this is for code that has to run on iOS as well as desktop, and "constantly writing to a file" is something I want to avoid, since I don't want it as a file anyway. Also ... I'd have to worry about maintaining that file, proactively trimming its size, etc.