Android logging levels

前端 未结 3 1661
猫巷女王i
猫巷女王i 2020-12-07 17:12

I\'m having a little difficulty configuring Android logging. Here\'s what my code looks like:

    if (Log.isLoggable(\"MY_TAG\", Log.VERBOSE)) {
        Log.         


        
3条回答
  •  误落风尘
    2020-12-07 17:31

    It seems that later versions of Android want /data/local.prop to be writable by root only. The adb push command appears to initially create files with granting everyone read/write access (because default file mask is 777). Android, wisely, ignores /data/local.prop since this can be a security risk.

    I have only experimented with Android 2.3.3, and 4.1.2. The former has no issues with reading a local.prop that is world writable, while the latter appears to silently ignore the file's contents.

    Creating a local.prop file as described in the original question:

    log.tag.MY_TAG=VERBOSE
    

    And then pushing it onto the device as follows seems to do the trick:

    adb push local.prop /data/local.prop
    adb shell chmod 644 /data/local.prop
    adb shell chown root.root /data/local.prop
    adb reboot
    

    You can double check to make sure that the values in local.prop were read by executing:

    adb shell getprop | grep log.tag
    

    So in summary:

    • /data/local.prop is only read during boot.
    • Later versions of Android appear to require that the permissions on the /data/local.prop file must be properly set, or it will not be read. The file must be writable by root only.

    Using adb shell setprop log.tag.MyAppTag VERBOSE also work. The issue is that the property values are lost after a reboot.

提交回复
热议问题