Android 5.0 How to correctly enable Isloggable (a) __ use detailed

Source: Internet
Author: User
Tags root access

Transferred from: http://blog.csdn.net/yihongyuelan/article/details/46409389

What is isloggable?

In the Android source code, we can often see the following codes:

[Java]View PlainCopy 
  1. Packages/apps/incallui/src/com/android/incallui/log.java
  2. Public static final String TAG = "Incall";
  3. Public Static final Boolean DEBUG = Android.util.Log.isLoggable (TAG, Android.util.Log.DEBUG);
  4. Public static void D (string tag, string msg) {
  5. if (DEBUG) {
  6. ANDROID.UTIL.LOG.D (tag, delimit (tag) + msg);
  7. }
  8. }
  9. Packages/apps/incallui/src/com/android/incallui/incallpresenter.java
  10. Private Incallstate Startorfinishui (Incallstate newstate) {
  11. LOG.D (This, "Startorfinishui:" + mincallstate + "+ newstate");
  12. //... ...  
  13. }

The Startorfinishui Log can be output normally only if the Android.util.Log.isLoggable return value is true. When will the Isloggable return true? How to quickly and easily open the isloggable and make log output normally?

This article is from Http://blog.csdn.NET/yihongyuelan reprint please be sure to indicate the source

Isloggable definition

What is isloggable? Isloggable is a method provided by Android.util.Log that checks the level of the specified tag, satisfies the output condition, returns true if satisfied, and returns false instead. Isloggable is defined in the source code as follows:

[Java]View PlainCopy 
  1. /**
  2. * Checks to see whether or not a log for the specified tag was loggable at the specified level.
  3. *
  4. * The default level of any tag are set to INFO. This means, above and including
  5. * INFO'll be logged. Before calls to a logging method you should check to see
  6. * If your tag should be logged. You can change the default level by setting a system property:
  7. * ' SetProp log.tag.<your_log_tag> <LEVEL> '
  8. * Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or suppress. Suppress would
  9. * Turn off all logging for your tag. You can also create a local.prop file the
  10. * Following in it:
  11. * ' log.tag.<your_log_tag>=<level> '
  12. * and place that in/data/local.prop.
  13. *
  14. * @param tag the tag to check.
  15. * @param level to check.
  16. * @return Whether or not, this was allowed to be logged.
  17. * @throws IllegalArgumentException is thrown if the tag.length () > 23.
  18. */
  19. Public static native boolean isloggable (String tag, int. level);
From the above definition, you can know:

1. Isloggable default level is Android.util.Log.INFO;

2. Only level >= info can be output, that is, level >= info isloggable returns True, and vice versa returns false;

3. You can change the default level of log by SetProp log.tag.<your_log_tag> <LEVEL>, such as adb shell SetProp log.tag.InCall D. These attributes can also be written to/data/local.prop in the form of log.tag.incall=d;

4. If the length of the tag exceeds 23 characters, the IllegalArgumentException exception will be thrown;

The 6 level of log is defined in the Android.util.Log class, as follows:

[Java]View PlainCopy 
  1. /**
  2. * Priority constant for the println method; Use LOG.V.
  3. */
  4. Public static final int VERBOSE = 2;
  5. /**
  6. * Priority constant for the println method; Use LOG.D.
  7. */
  8. Public static final int DEBUG = 3;
  9. /**
  10. * Priority constant for the println method; Use LOG.I.
  11. */
  12. Public static final int INFO = 4;
  13. /**
  14. * Priority constant for the println method; Use LOG.W.
  15. */
  16. Public static final int WARN = 5;
  17. /**
  18. * Priority constant for the println method; Use LOG.E.
  19. */
  20. Public static final int ERROR = 6;
  21. /**
  22. * Priority constant for the println method.
  23. */
  24. Public static final int ASSERT = 7;
The size of the log,level values of 6 levels corresponding to different grades increases with the increase of the log weight.

Isloggable Enable method

As mentioned earlier, isloggable is commonly used in custom log classes to determine whether to output log, such as code:

[Java]View PlainCopy  
  1. Packages/apps/incallui/src/com/android/incallui/log.java
  2. Public static final String TAG = "Incall";
  3. Public Static final Boolean DEBUG = Android.util.Log.isLoggable (TAG, Android.util.Log.DEBUG);
  4. Public static void D (string tag, string msg) {
  5. if (DEBUG) {
  6. ANDROID.UTIL.LOG.D (tag, delimit (tag) + msg);
  7. }
  8. }
  9. Packages/apps/incallui/src/com/android/incallui/incallpresenter.java
  10. Private Incallstate Startorfinishui (Incallstate newstate) {
  11. LOG.D (This, "Startorfinishui:" + mincallstate + "+ newstate");
  12. //... ...  
  13. }
If you want to output log in the Startorfinishui () method, you can do this in the following ways:

①. Modify the LOG.D to ANDROID.UTIL.LOG.D , use the Android.util.Log class instead of the Incallui custom Log class, recompile the system app and push it to the phone;

②. Modify the debug limit in the Com.android.incallui.Log , set the value of debug directly to True, or comment out if (debug). can also be isloggable (TAG, Android.util.Log.DEBUG) The Android.util.Log.DEBUG in is modified to Android.util.Log.INFO, which increases the level of Log, so that isloggable () returns True and the debug value is true;

③. Set Log.tag.InCall property values , SetProp log.tag.InCall D through adb shell, or write "Log.tag.incall=d" to/data/local.prop ( Do not include quotation marks, such as Local.prop does not exist, you need to create it yourself, set the permission to 644). Depending on the description in the definition, setting the property value needs to restart the Incallui process before the method is called. By modifying the method of the property value so that the return value of Isloggable () is true, the debug value is true.

The first way to directly modify, simple and rude, but if the number of changes is more cumbersome, and need to recompile the code.

The second way to modify points is uniform, but as with the first one, it also needs to be recompiled.

The third way to use attributes makes Isloggable return true, which is convenient and works well for user/userdebug/eng versions of devices. This method needs to be set Log.tag.InCall before the method is called, through the code:

[Java]View PlainCopy 
    1. Public Static final Boolean DEBUG = Android.util.Log.isLoggable (TAG, Android.util.Log.DEBUG);
As you can tell, because debug is a static variable, its value is set when the log class is loaded. If you want to make isloggable return to true, then SetProp needs to be set before the log class is loaded, so you need to restart the corresponding process after using SetProp, such as the com.android.incallui here. But some code in the framework also uses isloggable,framework to belong to each process, how do you restart the framework? You can use: [Java]View PlainCopy 
    1. ADB shell stop
    2. ADB shell start
The ADB shell stop kills the zygote process and all the child processes hatched by zygote. ADB shell Start restarts the zygote process, and the zygote process launches other Android core processes. When Zygote restarts, the framework-related resources are reloaded, and the properties are already set. This method is simple, but when the device restarts, all of the settings of the log.tag.<tag> will fail, and if you want to enable it again, you need to reset it.

It is also possible to add Log.tag.incall=d to the/data/local.prop file, which is similar to SetProp, which is to set the property value, but the advantage of this is that the Log.tag.InCall is still valid if the device is restarted after Setup. However, because of the permissions control of the/data directory, only the Userdebug/eng version can modify the/data/local.prop file. [/SYSTEM/CORE/INIT/PROPERTY_SERVICE.C] the load_override_properties () function has a/data/local.prop enable method.

Summary

The Enable method for Isloggable is as follows:

Figure 1 Comparison of isloggable enable scheme

If you just want to enable the Isloggable method of a process, setting properties through SetProp is a good choice, colleagues, if you want to restart the device is still valid, you need to set/data/local.prop, but/data directory only in userdebug/ Can only be written in the Eng version. If you want to set the Log.tag property in the user version and still work after a reboot, you can do the following:

1. Get root access to the user version of the system;

2. Append the Log.tag.incall=d to the/system/build.prop file;

3. ADB reboot restart the device;

The above plan you may be puzzled, since the user version gets root permissions, why not directly modify/data/local.prop? This is because if the user version is ro.debuggable=0, the/data/local.prop file will not be read when the system starts, and eventually the settings Log.tag property will not take effect. Detailed principles will be explored in the next article, "How does Android 5.0 correctly enable isloggable (i) __ principle analysis".

Android 5.0 How to correctly enable Isloggable (a) __ use detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.