I’d like to have a reusable logging method or function that spits out the name of the method it’s called from. Example:
- (void)exampleMethod {
CustomLog(); //Outputs "exampleMethod"
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Functions don’t know about their calling environment (at least not in a useful way). The only way is to use a macro instead. Inside the macro, you have access to the
selfand_cmdarguments that hold the receiver and current selector, as well as the__PRETTY_FUNCTION__macro that contains the human-readable name of the method as a C string.