I'm looking for a way to capture all NSLog output in an NSArray or any other memory structure, while keeping my console logs intact. I'm creating a tool that sends a copy of the latest X log lines to a server upon request. So far, these are the options that I ruled out:
- I can't redirect NSLog to a file as suggested here, as that would remove also all log messages from console.
- I tried swizzling NSLog with another custom function, but I'm having trouble finding how to swizzle C functions as opposed to class methods.
- Wrapping NSLog in my own CustomLog function is possible, but I'd rather have it as a last resort. The project is quite big and there are too many calls to replace. I'm also afraid of losing console output from libraries, where it would be hard to add my CustomLog.
I've been looking for a way to intercept NSLog output, or to capture logs after they've been printed in console, but I couldn't find anything that worked. Any suggestions?
Update: I ended up rethinking the approach, and I replaced all log calls through the code with my own logging method. It was extra work, but the flexibility to change implementation details paid in the end.