is NSLog() stored on the device (iPhone etc)? If so, where?
Asked Answered
W

6

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.

Weissman answered 12/7, 2011 at 11:54 Comment(0)
A
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.

Adon answered 12/7, 2011 at 12:11 Comment(3)
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/<DEVICE_NAME>Weissman
@Douglas K. Bell -- they are on the phone, but you'll need a tool like iPhone Explorer 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.Adon
but in my case, the folder only contains .crash file which contains the stack trace, but none of it contains the NSLog contents...Ectype
E
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)

Essentiality answered 10/8, 2012 at 6:37 Comment(4)
The python scripts to parse the .asl files is located at here and the details are on the archived copy of the original Blog PostSmelter
The original blog post mentioned in the answer above has moved. Fixed the link.Smelter
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 hereSmelter
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.Splat
A
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.

Adon answered 12/7, 2011 at 12:11 Comment(3)
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/<DEVICE_NAME>Weissman
@Douglas K. Bell -- they are on the phone, but you'll need a tool like iPhone Explorer 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.Adon
but in my case, the folder only contains .crash file which contains the stack trace, but none of it contains the NSLog contents...Ectype
A
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.

Ats answered 12/7, 2011 at 11:59 Comment(0)
A
3

Try using this for your NSLogs:

#define DEBUG

#ifdef DEBUG
 NSLog(@"Your tests outputs");
#endif
Aerometry answered 12/7, 2011 at 12:3 Comment(2)
Shouldn't that be 'NSLog(@"Your tests outputs");` (capital L)Terni
Better define your own macro and redefine it if not DEBUG, like in the PCH template of LinkedLigMcmahan
L
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.

Livable answered 12/7, 2011 at 13:36 Comment(2)
Logs can be a source of information disclosure. In the enterprise, I don't like to see any logging.Briannebriano
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.Tornado
F
-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.

Feticide answered 9/10, 2014 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.