Posts Tagged ‘Cocoa’

SOLogger: a Cocoa ASL Logging framework

Wednesday, August 19th, 2009

I spent some time recently putting together a Cocoa interface to the built-in Apple System Logging (ASL) facility.

Following Peter Hosey’s excellent blog series on ASL and some other tidbits on Cocoa-Dev, I fashioned small and simple Cocoa framework for integrating ASL’s multi-leveled logging into your project.


#import <SOLogger/SOLogger.h>

SOLogger *logger;

logger = [SOLogger loggerForFacility: @"com.example.MyApp" options:ASL_OPT_STDERR];

[logger debug:@"A debugging note on: %@", [NSDate date]];

[logger info:@"We just did something."];
[logger notice:@"That's going to leave a mark"];
[logger warning:@"WTF?"];
[logger alert:@"WTF!"];
[logger critical:@"OMG"];
[logger panic:@"OMG WTF!"];

An interesting feature of SOLogger (courtesy of ASL) is that you can create separate loggers for subsystems in your code, potentially logging them to separate destinations.

I host the SOLogger project on Bitbucket with a BSD License.

Check it out.

Running selected unit tests with GHUnit

Saturday, March 14th, 2009

I love the sanity that GHUnit brings to running and debugging unit tests. The under-documented Xcode 3 mojo needed to configure SenTest unit test bundles for debugging throws a wet towel on the practice of test-driven Cocoa development.

The current GHUnit distribution runs all unit tests found in your app or framework. I did some work today to enable running a selected test cases and individual unit tests.

This works similarly to the SenTestingKit’s otest tool. You specify a unit test case and/or test name to run as an argument to the GHUnit test application.

In the Xcode’s executable panel for the test application, add arguments of the form:

-Test UserTests
-Test UserTests/testEmptyUserName
-Test All

When you run or debug the test app, only the specified test case or individual test will be executed. The argument -Test All will run all available unit test cases.

The patch file is here and works for Mac OS X. To apply the patch:

$ cd your-GHUnit-project-directory
$ patch -p1 < path-to-patch-file

I’ve submitted the patch to Gabriel, so maybe it’ll make it into a future release.