AARON SMITH’S CODE ENDEAVOR

Apple System Log Cocoa Wrapper

Here’s a quick apple system log cocoa wrapper. Open the terminal, and type “man asl,” asl is the wrapper around syslog - which seems to be the first syslog for apple. The Console app (/Applications/Utilities/Console) shows all messages sent through asl.

Here’s a link to the files:

GDASLLog.h
GDASLLog.m
GDASLLogManager.h
GDASLLogManager.m

And here’s how you want to use it:

GDASLLog * log = [[GDASLLog alloc] initWithSender:@"MyAppName" facility:@"com.codeendeavor.MyAppName" connectsImmediately:TRUE];
 
//optionally set the file to write to. You'll still see logs in Console if you don't set this,
//but this way you can get the log file if needed.
[log setLogFile:@"/Library/Logs/MyApp"];
 
[log info:@"HELLO WORLD"];

And there’s a manager to hold references to your logs:

GDASLLogManager * gdLogMan = [GDASLLogManager sharedInstance];
[gdLogMan setLog:log forKey:@"logID"];
 
//GDASLLog * log = [gdLogMan getLogForKey:@"logID"];

I’ve been using this in an app to log some problems that were happening on another computer. I don’t leave these in when it’s ready to go. This just simplifies writing out some logs.

Enjoy.

  

1 Comment so far

  1. Tom Jones November 24th, 2009 2:40 pm

    Your quick example should be “connectImmediately” not “connectsImmediately” :-)

Leave a reply