Search code examples
iphonetracenslog

TRACE logging on iPhone


I am new to iPhone and trying to learn the sequence of methods invoked during application loading time.

After some googling, I found this that seems to be adequate: NSLog(@"Begin %@ initWithNibName", [[self class]description]); But is there a way to insert the method name instead of typing it myself? Is there even a better TRACE log command???

Also, I found this on the internet:

#define METHOD_LOG (NSLog(@"%@ %s\n%@", \
    NSStringFromSelector(_cmd), __FILE__, self))

But I don't know what it does and how to use it. I tried: -(id) init { METHOD_LOG("init"); ...... }

But doesn't compile.


Solution

  • I use this to log the current method or function (works for both):

    NSLog(@"%s", __FUNCTION__);
    

    To use the macro you quoted, you just type:

    METHOD_LOG;