tags:

views:

129

answers:

1

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?

+3  A: 

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.

Barry Wark
This is the best introduction to ASL I've found thus far:http://boredzo.org/blog/archives/2008-01-20/why-asl
Lawrence Johnston
Peter Hosey's series on ASL is definitely a must read. With GTM's GTMLogger+ASL, however, you can skip almost all the details and just use it.
Barry Wark
I did indeed end up using GTMLogger, and it does more or less exactly what I need.
Lawrence Johnston