For my Mac app I’d like to create a log file on disk similar to those produced by log4net windows side. Things I’d like include a date stamp, logging levels (Debug, Info, Warning, Error), etc, and I’d prefer not to have to roll my own from scratch.
Both VMWare fusion and JollysFastVNC do something similar to what I’m looking for, albeit without the log levels.
Logging to the console with NSLog() just doesn’t cut it for me.
How do I do this?
There are two system-level logging APIs on OS X: syslog and asl. The second, Apple System Logger, or ASL is quite powerful and can be used as the basis for application logging to the system console and/or to a separate file.
The ASL API is straight C. It’s not hard to wrap in Objective-C, however. The Google Toolbox for Mac has a nice logging system, including ASL support (see GTMLogger+ASL) and a ring-buffer implementation.