Using Log.d () or Log.e () in my code

I used Log.d() and Log.e() through my Android app for debugging. I would like to know if I debug my application like this, will the user see all those debug statements that I have embedded? Do I need to do something special so that the user does not see the debug log, even if they have connected 'adb logcat' ?

Thanks.

+7
source share
7 answers

Think about it: isLoggable ()

Checks if the log is logged for the specified tag at the specified level. By default, any tag is set to INFO. This means that any level above and including INFO will be registered. Before you make any calls to the logging method, you should check if the tag should be logged. You can change the default level by setting the system property: setprop log.tag.<YOUR_LOG_TAG> <LEVEL> Where the level is VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT or SUPPRESS. SUPPRESS will disable all entries for your tag. You can also create a local.prop file with the following in it: log.tag.<YOUR_LOG_TAG>=<LEVEL> and put it in /data/local.prop

Personally for releases, I delete debug logs and save error logs using Proguard.


Better wrap it like this:

 public class MyLog { public static void d(String tag, String msg) { if (Log.isLoggable(tag, Log.DEBUG)) { Log.d(tag, msg); } } public static void i(String tag, String msg) { if (Log.isLoggable(tag, Log.INFO)) { Log.i(tag, msg); } } // and so on... 

You can set the logging level by issuing the adb command

+2
source

In some cases, registration applications can be very bad: http://web.archive.org/web/20121222023201/http://vbsteven.com/archives/535

You can use ProGuard to automatically delete all of them:

 -assumenosideeffects class android.util.Log { public static *** d(...); public static *** e(...); } 
+7
source

Not only the user (or any application with access to the log) sees your logs, but your logs also make your application run slower and use more battery power.

Writing a log, especially from Java, is probably a lot more expensive than you think: just creating a string in Java is a lot of work.

+4
source

There are applications on the market that allow users to view logs even without connecting to a development environment.

CatLog is the one I personally used and it will show you everything.

What I did in my application was to create a wrapper class that I can disable using a boolean flag. This has the added benefit that the TAG parameter is the overall bandwidth of my code.

 public class QLog { private static final String TAG = "MyAppTag"; private static final boolean DEBUG_MODE = true; public static void d(String msg) { if(DEBUG_MODE) { Log.d(TAG, msg); } } ... } 
+1
source

As stated in android.developer.com

when you create a string to pass to Log.d, the compiler uses StringBuilder and there are at least three distributions: the StringBuilder itself, the buffer, and the String object. Actually, there is another distribution and copying of the buffer, and even more pressure on gc. This means that if your log message is filtered, you may be doing a lot of work and you will get significant overhead.

here is the link: http://developer.android.com/reference/android/util/Log.html

+1
source

They can be used in development. Upon release, it is better to delete or obfuscate the message to protect PII (personal information). The answer here is very useful: Android Log.v (), Log.d (), Log.i (), Log.w (), Log.e () - When to use each?

Here you will learn how to work with these magazines when releasing software. Delete all debug log calls before publishing: are there any tools for this?

+1
source

If your user is a developer and connects the device to a developing machine and LogCat is open, he will write all the logs to Logcat if he inserts this application. When you are going to publish the application to the end user, you must delete these logs.

0
source

All Articles