Detailed NSLog() via a Preprocessor Macro

/ Published in: Objective C
Save to your folder(s)

Ever needed to see more context surrounding your NSLog statement to help you debug in the console?

Copy this code and paste it in your HTML
  1. #define DetailedLog(str, args...) NSLog\
  2. (@"\n-------------\nBetter Log\n%s:%d\n%@\n[%s]\n\n[%@]\n-------------\n",\
  3. strrchr(__FILE__, '/'), __LINE__, self, sel_getName(_cmd),\
  4. [NSString stringWithFormat:str , ## args ] )
  6. // this function was improved to work in functions as well as methods:
  7. #define DetailedLog(str, args...)\
  8. NSLog(@"\n-------------\nBetter Log\n%s:%d\n%s\n\n[%@]\n-------------\n",\
  9. strrchr(__FILE__, '/'), __LINE__, __PRETTY_FUNCTION__,\
  10. [NSString stringWithFormat:str , ## args ] )


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.