Ensembles and CocoaLumberjack

I’ve switched one of my apps over to using CocoaLumberjack for logging, so that I can redirect logging to a file on disk, and then when I need to upload a crash log to HockeyApp, I can include some recent log data.  Often this is invaluable in figuring out what really went wrong.

I’m working with Drew McCormack’s Core Data Ensembles project for sync, and wanted to include the Ensembles logging output in my log files. Ensembles has its own CDELog method, which now supports calling through a callback method.

Setting this up is easy enough. Somewhere early in the launch of your app, probably where you set up CocoaLumberjack, set up the Ensembles logging callback:

CDESetLogCallback(FDSLogBridge);
 
And implement this function:

void FDSLogBridge(NSString *format, ...)
{
    va_list arglist;
    va_start(arglist, format);
    DDLogvCError(format, arglist);
    va_end(arglist);
}

The DDLogv variants of the DDLog methods, like NSLogv for NSLog, take a variadic argument list. This is what lets you pass on the arguments without actually knowing what they are.

Â