iosobjective-ccocoa-touchcocoalumberjack

CocoaLumberjack Log App Crash


First of all I have been reading some threads about CocoaLumberjack and I have not been able to find solution to this question:

I'm using CocoaLumberjack to Log in my app. But I want to Log the app crashes too.

I have tried this:

void uncaughtExceptionHandler(NSException *exception) {
    DDLogError(@"CRASH: %@", exception);
    DDLogError(@"Stack Trace: %@", [exception callStackSymbols]);
    // Internal error reporting

    // Send log to SOA

}

But I'm getting this error in the appDelegate, in other places works well:

Use of undeclared identifier '_cmd'; did you mean 'dcmd'?

Is there another way to do this?.


Solution

  • _cmd is a shortcut for the current selector, or Objective-C method that is being called. For instance, in a class that implemented a method like this:

    @implementation MDAppController
    
    - (void)applicationWillFinishLaunching:(NSNotification *)notification {
        NSLog(@"[%@ %@]", NSStringFromClass([self class]),
                              NSStringFromSelector(_cmd));
    }
    
    @end
    

    it would print out:

    [MDAppController applicationWillFinishLaunching:]

    You're running into problems trying to use DDLogError() from within that uncaughtExceptionHandler() function because it's a C function and not an Objective-C method, so _cmd is undefined.

    You should use DDLogCError() instead of DDLogError(), since the former is intended for use in C functions rather than Objective-C methods.