Log the method name in objective-C?

Posted by vodkhang on Stack Overflow See other posts from Stack Overflow or by vodkhang
Published on 2010-05-05T02:44:25Z Indexed on 2010/05/05 2:48 UTC
Read the original article Hit count: 260

Filed under:
|
|

Currently, we are defining ourselves an extended log mechanism to print out the class name and the source line number of the log.

#define NCLog(s, ...) NSLog(@"<%@:%d> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
    __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])

For example, when I call NCLog(@"Hello world"); The output will be: Hello world Now I also want to log out the method name like: Hello world

So, this would make our debugging become easier when we can know which method is getting called. I know that we also have XCode debugger but sometimes, I also want to do debugging by logging out.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone