Objective-C Language Logging NSLog vs printf


NSLog(@"NSLog message");
printf("printf message\n");


2016-07-16 08:58:04.681 test[46259:1244773] NSLog message
printf message

NSLog outputs the date, time, process name, process ID, and thread ID in addition to the log message. printf just outputs the message.

NSLog requires an NSString and automatically adds a newline at the end. printf requires a C string and does not automatically add a newline.

NSLog sends output to stderr, printf sends output to stdout.

Some format-specifiers in printf vs NSLog are different. For example when including a nested string, the following differences incur:

NSLog(@"My string: %@", (NSString *)myString);
printf("My string: %s", [(NSString *)myString UTF8String]);