Reputation: 1084
I have started a new project on iPad.I would like to know the method name and class name from which a particular message is sent to console while printing the message.Is there any way to print class & method names along with the log statement automatically.Please help and make my debugging easier thanks in advance.
Upvotes: 2
Views: 5270
Reputation: 7708
The below is the way I used in my app
NSLog(@"%@",NSStringFromClass([self class]));
Also see improved logging section in Apple documentation. Improved logging in Objective-C
-anoop
Upvotes: 2
Reputation: 151
If you want the classname as an NSString, use code below;
[[myObject class] description]
Upvotes: 1
Reputation: 86651
NSLog(@"%@ %s", [self className], sel_getName(_cmd));
As _cmd
starts with an underscore, it's potentially something you might not be able to rely on in the future, but everybody seems to use it for diagnostic logging.
Upvotes: 2