In Xcode Organizer, Console - I can read the NSLog
output, but not printf()
. Is this possible to read printf()
result on the real device, the same like in simulator?
Easiest solution would be to overload printf function globally in your project and replace it with NSLog output
int printf(const char * __restrict format, ...)
{
va_list args;
va_start(args,format);
NSLogv([NSString stringWithUTF8String:format], args) ;
va_end(args);
return 1;
}
As Nick Lockwood said in one of the comments above, printf prints to stdout but NSLog prints to stderr. You can use fprintf to print to stderr (the Xcode console) instead of using printf, like this:
fprintf(stderr, "This prints to the Xcode debug console");
You can run the following command to print only to device's console:
syslog(LOG_WARNING, "log string");
You will also need to #include <sys/syslog.h> for syslog and LOG_WARNING to be explicitly declared
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With