CocoaLumberjack Log App Crash
Asked Answered
D

3

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

Dashboard answered 27/2, 2014 at 16:43 Comment(0)
D
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.

Dumbbell answered 27/2, 2014 at 19:27 Comment(1)
Wow, Thanks for the reply you were right!. Now works perfect and the error is printed in my log :)Dashboard
C
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

Carloscarlota answered 27/2, 2014 at 20:3 Comment(0)
S
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.

Somber answered 7/3, 2014 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.