NSLog Performance Issue

Discussion in 'iOS Programming' started by walty, Sep 19, 2008.

  1. walty macrumors member

    Joined:
    Jul 15, 2008
    #1
    Hi,

    I have finished implementation of an iPhone app, and now is trying to finetune the performance. Throughout my code, I have put a LOT of NSLog statements for debug.

    I wonder is there any way for me to DISABLE those NSLog statements (say, by setting a compilation flag) for distribution. I know the NSLog statements will eventually be ignored when run on device, but I don't even want the arguments on NSLog statements to be evaluated.

    I know I may comment all the statements, but most of NSLog are useful for future debugging. I don't want to remove & restore them again and again.

    Any advice will be greatly appreciated.

    Thanks.

    have a nice day
    walty
     
  2. Sbrocket macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #2
    No, there is no convenient preprocessor flag as with NSAssert() macros. What I did is make a debugLog() macro that is defined as NSLog() when a certain preprocessor macro is defined (DEBUG, in my case) and nothing elsewise. It looks like this:

    Code:
    #ifdef DEBUG
    	#define debugLog(...) NSLog(__VA_ARGS__)
    #else
    	#define debugLog(...)		// Nothing
    #endif
    
    Then you can just do a simple find & replace to switch all your NSLog() statements with debugLog().

    Oh, and the NSLog() messages aren't ignored on the device - the messages will still get logged to the device's system logs, even if you distribute the app, so you'll probably want to do something like this to make sure that your logging statements don't get compiled into release or distribution builds.
     
  3. walty thread starter macrumors member

    Joined:
    Jul 15, 2008
    #3
    Thanks, it works great :)

     

Share This Page