Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?.

like image 227
Mikel Sanchez Avatar asked Feb 27 '14 16:02

Mikel Sanchez


Video Answer


2 Answers

_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.

like image 168
NSGod Avatar answered Sep 23 '22 00:09

NSGod


in a C function there is no hidden self, and no hidden _cmd, but never fear...

there are a family of logging functions for you:

#define DDLogCError(frmt, ...)   LOG_C_MAYBE(LOG_ASYNC_ERROR,   ddLogLevel, LOG_FLAG_ERROR,   0, frmt, ##__VA_ARGS__)
#define DDLogCWarn(frmt, ...)    LOG_C_MAYBE(LOG_ASYNC_WARN,    ddLogLevel, LOG_FLAG_WARN,    0, frmt, ##__VA_ARGS__)
#define DDLogCInfo(frmt, ...)    LOG_C_MAYBE(LOG_ASYNC_INFO,    ddLogLevel, LOG_FLAG_INFO,    0, frmt, ##__VA_ARGS__)
#define DDLogCVerbose(frmt, ...) LOG_C_MAYBE(LOG_ASYNC_VERBOSE, ddLogLevel, LOG_FLAG_VERBOSE, 0, frmt, ##__VA_ARGS__)

similar to NSAssert vs NSCAssert

like image 22
Grady Player Avatar answered Sep 25 '22 00:09

Grady Player