-
-
Save Longhanks/8315cfdb8ec5f4150936b919b2e47fd5 to your computer and use it in GitHub Desktop.
Redirect stdout/stderr to NSLog on iOS Simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
static int redirect_nslog(const char *prefix, const char *buffer, int size) | |
{ | |
NSLog(@"%s (%d bytes): %.*s", prefix, size, size, buffer); | |
return size; | |
} | |
static int stderr_redirect_nslog(void *inFD, const char *buffer, int size) | |
{ | |
return redirect_nslog("stderr", buffer, size); | |
} | |
static int stdout_redirect_nslog(void *inFD, const char *buffer, int size) | |
{ | |
return redirect_nslog("stdout", buffer, size); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
setlinebuf(stdout); | |
setlinebuf(stderr); | |
stdout->_write = stdout_redirect_nslog; | |
stderr->_write = stderr_redirect_nslog; | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment