0

We all knew that NSLog() is quite expensive and it's not good to use in production. Unless its specific. I have gone through different stack overflow links related to this question. I need to print a object both in release and debug mode with same printing method. I can't put condition like if debug mode or release. Because i want same information in both release and debug modes. How to achieve this. any idea? Have been looking into google but i didn't get. There is a related post Do I need to disable NSLog before release Application?

Thanks

Community
  • 1
  • 1
selva
  • 799
  • 2
  • 13
  • 25
  • 1
    I don't understand. Why not use `NSLog()`? – trojanfoe Sep 02 '14 at 13:02
  • Where do you want to log when you're in release mode ? I use https://github.com/CocoaLumberjack/CocoaLumberjack, it can log on local files... Some libs also give distant logging solutions... – Vinzzz Sep 02 '14 at 13:02
  • @trojanfoe: Copy pasting from another stack overflow. NSLog is pretty slow. Why? NSLog will do two things 1) write log messages to Apple System Logging(ASL), 2) if the app runs in xcode it write to stderr too.The main problem lays in the first one. In order to achieve thread safe, every time NSLog is called, it opens an connection to ASL facility, sends message, and closes the connection. The connection operation is very expensive. Another reason is that NSLog spends some time to get the timestamp to log. – selva Sep 02 '14 at 13:25
  • @vinzzz: In console i want to write. – selva Sep 02 '14 at 13:27
  • 1
    Why would you want to have NSLog's in release? NSLog's are for debugging. – Jasper Sep 02 '14 at 13:36
  • @jasperPol: That's what i wanted. I don't want use NSLog in the release. What is the alternate to use in release which does the same as NSLog(). Because we need to write log into device console. – selva Sep 03 '14 at 04:57
  • I think you're a bit confused with what release is. Release is the target which you use to push to the AppStore (hence, release). I really don't understand why you even want to try to write logs in a device console which will never be read in the first place. If you want to read logs in release, check out the framework @Vinzzz mentioned in his comment. – Jasper Sep 03 '14 at 08:09

0 Answers0