Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Foundation equivalent for NSLog

What is the closest Core Foundation function to the functionality of NSLog?

like image 965
Nick Moore Avatar asked Jun 17 '10 08:06

Nick Moore


People also ask

Is core and foundation the same thing?

CoreFoundation is written in C while Foundation is written in Objective-C; Foundation has a lot more classes; CoreFoundation is the common base of Foundation and Carbon.

Where does NSLog write to?

NSLog outputs messages to the Apple System Log facility or to the Console app (usually prefixed with the time and the process id).


1 Answers

CFShow() is similar, but without the prefix stuff. Or, as wbyoung says, use NSLog(). If you don’t want to use Objective-C, the following is perfectly valid (although it requires linking against Foundation.framework):

#if __cplusplus
extern "C" {
#endif
void NSLog(CFStringRef format, ...);
void NSLogv(CFStringRef format, va_list args);
#if __cplusplus
}
#endif

int main (int argc, const char * argv[])
{
    NSLog(CFSTR("Hello, World! %u"), 42);
    return 0;
}
like image 102
Jens Ayton Avatar answered Oct 26 '22 18:10

Jens Ayton