I\'m examining the feasibility of porting an existing Windows MFC control to OS X/Carbon. My test bed is a C++ Carbon application generated using the XCode 3 Wizard.
I\
First off, Carbon isn't and won't be available in 64-bit. If Apple ever drops 32-bit Mac OS X (which it's safe to assume will happen sooner or later), your app will not run. Use Cocoa.
That said, there are several ways to do logging:
NSLog
This is a Cocoa function, but you can use it in Carbon apps, too. Link against the Foundation framework, but don't include the header. Declare it yourself:
int NSLog(CFStringRef format, ...);
You'll pass a CFSTR literal as the format:
NSLog(CFSTR("Count: %u"), count);
The advantage of NSLog is that you can print CF property-list objects (strings, data objects, dates, numbers, arrays, and dictionaries) using the %@ formatter. For example:
CFArrayRef array = /*...*/;
NSLog(CFSTR("Array: %@"), array);
printf/fprintf
The old C standard library standbys. #include
to get them. It doesn't matter much in a GUI app, but you should use stderr for cleanliness: fprintf(stderr, "Count: %u\n", count);
syslog
About as old as f?printf, I'd guess, but more powerful. This is an actual logging system, not just writing to a file. You can specify things like priority, allowing you to suppress your debug log messages on beta testers' systems while still being able to read them on your own system. (Final releases should not contain logging code at all.)
asl_log
Part of Apple System Logger, Apple's more general replacement for syslog. I have a series of posts about ASL on my blog.