Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

android - Logcat won't display Log.d messages

I'm developing an Android application and I would like to have some way to print debug statements as my code runs. Fortunately for me, Logcat was able to print out Log.d messages when I run my application on an Android 2.3.3 (API 10) emulator.

However, when I tested the same exact application on a physical device (Samsung Galaxy S4 Android 4.2.2) I was unable to see anything other than dalvikvm and AndroidRuntime messages.

com.android.internal.os.RuntimeInit <<<<<<
07-28 04:49:24.165: DEBUG/AndroidRuntime(6378): CheckJNI is OFF
07-28 04:49:24.165: DEBUG/AndroidRuntime(6378): setted country_code = USA
07-28 04:49:24.165: DEBUG/AndroidRuntime(6378): setted countryiso_code = US
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): setted sales_code = VZW
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): readGMSProperty: start
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): readGMSProperty: already setted!!
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): readGMSProperty: end
07-28 04:49:24.175: DEBUG/AndroidRuntime(6378): addProductProperty: start
07-28 04:49:24.185: DEBUG/dalvikvm(6378): Trying to load lib libjavacore.so 0x0
07-28 04:49:24.185: DEBUG/dalvikvm(6378): Added shared lib libjavacore.so 0x0
07-28 04:49:24.195: DEBUG/dalvikvm(6378): Trying to load lib libnativehelper.so 0x0
07-28 04:49:24.195: DEBUG/dalvikvm(6378): Added shared lib libnativehelper.so 0x0
07-28 04:49:24.385: DEBUG/AndroidRuntime(6378): Calling main entry com.android.commands.pm.Pm
07-28 04:49:26.978: DEBUG/AndroidRuntime(6378): Shutting down VM
07-28 04:49:26.988: DEBUG/dalvikvm(6378): GC_CONCURRENT freed 157K, 21% free 627K/788K, paused 1ms+0ms, total 4ms
07-28 04:49:26.988: DEBUG/jdwp(6378): Got wake-up signal, bailing out of select
07-28 04:49:26.988: DEBUG/dalvikvm(6378): Debugger has detached; object registry had 1 entries
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): CheckJNI is OFF
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): setted country_code = USA
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): setted countryiso_code = US
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): setted sales_code = VZW
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): readGMSProperty: start
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): readGMSProperty: already setted!!
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): readGMSProperty: end
07-28 04:49:27.458: DEBUG/AndroidRuntime(6420): addProductProperty: start
07-28 04:49:27.468: DEBUG/dalvikvm(6420): Trying to load lib libjavacore.so 0x0
07-28 04:49:27.478: DEBUG/dalvikvm(6420): Added shared lib libjavacore.so 0x0
07-28 04:49:27.478: DEBUG/dalvikvm(6420): Trying to load lib libnativehelper.so 0x0
07-28 04:49:27.478: DEBUG/dalvikvm(6420): Added shared lib libnativehelper.so 0x0
07-28 04:49:27.649: DEBUG/AndroidRuntime(6420): Calling main entry com.android.commands.am.Am
07-28 04:49:27.659: DEBUG/dalvikvm(6420): Note: class Landroid/app/ActivityManagerNative; has 169 unimplemented (abstract) methods
07-28 04:49:27.719: DEBUG/AndroidRuntime(6420): Shutting down VM
07-28 04:49:27.729: DEBUG/dalvikvm(6420): GC_CONCURRENT freed 157K, 20% free 666K/828K, paused 0ms+1ms, total 3ms
07-28 04:49:27.729: DEBUG/jdwp(6420): Got wake-up signal, bailing out of select
07-28 04:49:27.729: DEBUG/dalvikvm(6420): Debugger has detached; object registry had 1 entries

I'm not exactly sure what is going on since Logcat is correctly targeting my physical device, it shows up on adb devices, and USB Debugging is on.

I've tried using Log.e but that had no effect on the output.

I even set android:debuggable="true" in AndroidManifest.xml.

Is there something I'm missing here? Why won't Logcat display my debug messages when running my app on my physical device?

EDIT: I tried the same app on a Android 4.2.2 emulator and Logcat works as expected with the emulator, but there's still the problem with Logcat through the USB device. Instead of the verbosity of a normal Logcat printout, the block I posted is the only thing I see on the Verbose log level.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It might because of some phones disabled log to enhance performance.

For example, my phone HUAWEI P9 lite, i have to do the following steps to make Log.d works:

  1. Dial *#*#2846579#*#*
    • The number might vary, you should do some search to get secret code for your phone.
  2. Come to ProjectMenu page
  3. Click Background Settings
  4. Click LOG Settings
  5. Check AP Log.
  6. For unknown reason, it automatically checked all logs when reopen LOG Settings.

enter image description here

[UPDATE]

Just now it happen again after I pull from git, adb shell shows this:

open '/dev/hwlog_switch' fail -1, 13. Permission denied
log switch off, only log_main and log_events will have logs!

I test with new project and it got log, only this old project has issue. I tried rebuild the app, re-enable the log steps above, and even reboot phone, but still no luck.

Then I uninstall the app (Or all relevant productFlavors apps) in phone and reinstall, the log was back.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...