Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLog on the device, is that a problem or must i remove that?

I have read this post: what happens to NSLog info when running on a device?

...but wondering if NSLog is a problem when distributing the app such as filling up the memory or something? I am only interested to see it when i test the consistency of my input data to the database.

The reason is that I have NSLog to control when i load the data into my database in the simulator. I could remove it when i upload but it would be good if i do not need to?

like image 942
PeterK Avatar asked Jun 20 '11 04:06

PeterK


People also ask

How do I turn off NSLog mode?

You can turn off NSLog per . m file by simply including the follow line at the top of the . m file: #define NSLog(...)

Where does NSLog write to?

NSLog outputs messages to the Apple System Log facility or to the Console app (usually prefixed with the time and the process id). Many of the system frameworks use NSLog for logging exceptions and errors, but there is no requirement to restrict its usage to those purposes.


2 Answers

You should remove it. For example if you log contents of a UITableViewCell (in -tableView:cellForRowAtIndexPath:), it can make a big difference in performance, especially on slower hardware.

Use a macro to keep NSLog output in Debug mode, but remove it from Release mode. An example can be found on the following site: http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog

like image 56
Wolfgang Schreurs Avatar answered Oct 02 '22 09:10

Wolfgang Schreurs


I use a set of macros in my pch file that are quite handy for this.

See http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ for details.

#ifdef DEBUG
  #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
  #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
  #define DLog(...) do { } while (0)
  #ifndef NS_BLOCK_ASSERTIONS
    #define NS_BLOCK_ASSERTIONS
  #endif
  #define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#endif

#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)
like image 33
Abizern Avatar answered Oct 02 '22 09:10

Abizern