9

Should all NSLog() calls be deleted in the final app for iTunes?

In my iOS app, I've got lots of NSLog() for debug. Should I conditionally code them out before uploading to iTunes?

This is for an app for: iPhone, iPod, iPad

Thanks.

Doug Null
  • 7,989
  • 15
  • 69
  • 148

6 Answers6

7

I'll answer the OP's question in the title about where the logs are stored on the device. NSLog() uses the ASL (Apple System Logger). Programmatically, you can only read the last 256 entries (which is what Xcode shows in the Organizer, for example).

However, if you want to access the full files, they are stored in:

/private/var/log/DiagnosticMessages

When you look into that directory (note: device must be Jailbroken), you'll find a long list of *.asl files.

I found a tool to parse those files, but I haven't tried it yet, so YMMV:

Parsing Apple System Log (ASL) files on iOS and OSX for Fun and Evidence (and a Python script to do it for you)

Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91
Chris De Laet
  • 71
  • 1
  • 3
  • The python scripts to parse the .asl files is located at [here](https://code.google.com/p/ccl-asl/) and the details are on the archived copy of [the original Blog Post](https://web.archive.org/web/20120914082712/http://digitalinvestigation.wordpress.com/2012/06/18/parsing-apple-system-log-files-osx-ios) – Ashutosh Jindal Nov 14 '13 at 19:35
  • The original blog post mentioned in the answer above has moved. Fixed the link. – Ashutosh Jindal Nov 14 '13 at 19:38
  • The python scripts linked in the above article still work me! iOS_asl_power_timeline.py used to generate the graph of the battery status seems to have a bug which I have suggested a fix for [*here*](http://is.gd/MSMG0t) – Ashutosh Jindal Nov 14 '13 at 21:23
  • May it be that the 256 entries have changed? I can see far more lines in the device console (under Devices > Your Device) of Xcode 7.3. Currently there are about 800 entries, but I think here are all NSLog statements shown since I opened this window. – testing Apr 28 '16 at 14:07
6

You don't have to remove all of them; in fact, they can be useful if your app crashes on a user's phone and you want them to send you a crash log. When a user syncs his/her phone, the crash log is located in the folder

~/Library/Logs/CrashReporter/MobileDevice/<DEVICE_NAME>

If you have NSLog()s you may gain useful information just as you would when debugging. As the others pointed out, don't overdo it, but it they could end up being useful.

Chris Gregg
  • 2,376
  • 16
  • 30
  • Is there a risk of the log getting too big on a user's iOS device? And, on my iPhone, how do I get to: ~/Library/Logs/CrashReporter/MobileDevice/ – Doug Null Jul 16 '11 at 13:16
  • @Douglas K. Bell -- they are on the phone, but you'll need a tool like [iPhone Explorer](http://www.macroplant.com/iphoneexplorer/) to get to them (I'm not sure where they are stored). The log files are in the Home directory on your *Mac* after you sync the phone. – Chris Gregg Jul 16 '11 at 16:27
  • but in my case, the folder only contains .crash file which contains the stack trace, but none of it contains the NSLog contents... – Zennichimaro May 23 '16 at 03:05
3

Yes, We should remove all the NSLog() calls before uploading to iTunes. That is done mainly for better performance.

Even if u dont remove them, no problem. It will be approved. But if u have lot NSLog() s, the that will def. affect the performance.

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
3

Try using this for your NSLogs:

#define DEBUG

#ifdef DEBUG
 NSLog(@"Your tests outputs");
#endif
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • Shouldn't that be 'NSLog(@"Your tests outputs");` (capital L) – Jonathan. Jul 12 '11 at 12:09
  • Better define your own macro and redefine it if not DEBUG, like in the [PCH template of LinkedLig](https://github.com/julian-weinert/LinkedLog/blob/master/JWLinkedLog/pch_file.xctemplate/___FILEBASENAME___.pch) – Julian F. Weinert Feb 19 '15 at 15:16
1

Not all. You should keep the error logs. That will make it easy to locate if there is any error or crash. Its possible to see NSLog messages using Organizer too.

karim
  • 15,408
  • 7
  • 58
  • 96
  • Logs can be a source of information disclosure. In the enterprise, I don't like to see any logging. – jww Sep 06 '12 at 18:30
  • 1
    Logging can be quite useful and secure if done correctly. Obviously don't do anything stupid such as log a key or something important like that, but having a log say something such as `received error code 50063 in function f` is pretty useful. Especially when error code 50063 can appear in 100 places. – rady Dec 26 '15 at 19:33
-2

You dont need to remove NSLogs if they added against DEBUG mode. So even if your app crashes and if it contains user personal data, it will be removed by ios. So do not worry about user data and NSLog. Refer https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/AnalyzingCrashReports/AnalyzingCrashReports.html Still if you want you can use this PJiOSAppConsole in your application. It will keep logs in your application only. You can use it at runtime by adding snippet in #ifdef then remove whenever you want to go to live. Easy to integrate and use.

Volvorine
  • 1
  • 2