Detailed NSLog() via a Preprocessor Macro


/ Published in: Objective C

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 ] )
  5.  
  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 ] )

URL: http://www.degutis.org/dev/2009/04/14/detailedlog/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.