4

I am about to release an app. Should I remove Log statements and e.printStackTrace() within the catch statements ?

4

4 に答える 4

4

Logs are essential troubleshooting resources, even for deployed software.

I would limit logging for production releases (perhaps even limit it to "only log in emergencies"). But I would not categorically say "no logging".

Here is a good discussion (with some good guidelines):

PS: Having said that, I hasten to add:

No, you should not have any "debug" or "informational" logging in a production release.

Which is exactly what the Android documentation, cited in the above links, also says.

于 2012-07-02T23:39:02.863 に答える
2

This is generally considered to be a good practice because:

  • If your log statements are enclose inside if statements on a debug flag, and you set that flag to false then when you compile your project, these statements are automatically left out, reducing the size of your apk, though not by much.
  • Since the log is shared with every other app, it is considerate to not have these messages in a production app as it will clutter other developer's logcat up when they debug.
  • Sometimes, you may be logging sensitive data like signatures, keys, passwords, emails, usernames etc. Disabling the logging can prevent your app from accidentally leaking such information.
于 2012-07-02T23:38:34.423 に答える
1

Sometimes having logs enabled can create security issues. Most Android applications don't need to worry about this for several reasons, but I would personally just get in the habit of disabling developer based features unless you want users to help you debug issues on other devices which isn't common practice in my experience.

于 2012-07-02T23:36:34.253 に答える
0

The answer is YES.

You can hide them adding some lines to the proguard.cfg file.

-keep class * extends android.app.Activity
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** e(...);
    public static *** i(...);
}

After the app has been signed no one will be able to read debug, error and info logs. Hope it works.

于 2012-07-02T23:57:17.143 に答える