6

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

oguz ismail
  • 1
  • 16
  • 47
  • 69
Mikel Sanchez
  • 2,870
  • 1
  • 20
  • 28

3 Answers3

11

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

NSGod
  • 22,699
  • 3
  • 58
  • 66
6

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

Grady Player
  • 14,399
  • 2
  • 48
  • 76
2

Yeap, you should be using DDLogC* for now. In the next version (2.0), DDLogError will work for both Obj-c methods and C functions.

Bogdan
  • 101
  • 2