adb shell 基础: 看日志神器logcat
访问量: 7846
refer to: http://developer.android.com/tools/debugging/debugging-log.html
只要是在Android 的java代码中,使用了 Log.d() 的语句,就会保存LOG信息, 就可以通过 adb shell logcat 来读取。
verbose/debug/information/warning/error 总共有5种形式。
$ adb shell (支持 df, ls, ll , top, ps, cat ,echo, touch 等 命令。)
/> logcat
然后就会发现,打印出来的都是实时的log. (都是 /dev/log下
shell@android:/ $ logcat --------- beginning of /dev/log/main D/wpa_supplicant( 444): wpa_s 0x40f4d7a8 cmd SIGNAL_POLL D/wpa_supplicant( 444): RX ctrl_iface - hexdump(len=11): 53 49 47 4e 41 4c 5f 50 4f 4c 4c D/wpa_supplicant( 444): nl80211: survey data missing! D/wpa_supplicant( 444): ctrl_iface: SIGNAL_POLL D/wpa_supplicant( 444): wpa_s 0x40f4d7a8 cmd SIGNAL_POLL D/wpa_supplicant( 444): RX ctrl_iface - hexdump(len=11): 53 49 47 4e 41 4c 5f 50 4f 4c 4c D/wpa_supplicant( 444): ctrl_iface: SIGNAL_POLL D/wpa_supplicant( 444): nl80211: survey data missing! E/BatteryService( 348): set value: false E/BatteryService( 348): set value: true E/BatteryService( 348): set value: true --------- beginning of /dev/log/system I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...}
上面打印的都是 /dev/log 下的文件, 现在看来,有这么几个文件:
shell@android:/dev/log $ ls -al crw-rw-rw- root log 10, 47 2015-04-11 14:08 events crw-rw--w- root log 10, 44 2015-04-11 14:08 exception crw-rw--w- root log 10, 48 2015-04-11 14:08 main crw-rw--w- root log 10, 46 2015-04-11 14:08 radio crw-rw--w- root log 10, 45 2015-04-11 14:08 system
比较奇怪的是, 10, 47, 10, 44 并不是文件的大小, 我们使用 cat 命令可以查看,但是看到的却是部分乱码. 应该是android 直接把日志给压缩了? 不清楚。 所以还是建议用 logcat | grep 来查看。
PushLogAC2317[ReceiverDispatcher-45]PushState get action :com.huawei.intent.action.PUSH(pushagent/null:PushLogAC2317[ReceiverDispatcher-45]enter ConnectMgrProcessor:onReceive(intent:Intent { act=com.huawei.android.push.intent.MSG_SENT (has extras) } context:com.huawei.android.pushagent.PushService@41e84328(puPushLogAC2317[ReceiverDispatcher-45]enter AlarmTools:setDelayAlarm(intent:Intent { act=com.huawei.android.push.intent.HEARTBEAT_RSP_TIMEOUT (has extras) } interval:10000ms, context:com.huawei.android.pushageAlarmManagerWakeup alarm[0] {2015 4 月 11 14:50:10 +0800} (com.huawei.android.pushagent) repeatInterval: 0w(�PB�(U��PushLogAC2317[ReceiverDispatcher-45]PushState get action :com.huawei.android.push.intent.MSG_SENT(pushagent/null:-1)J�xx�(UBFdalvikvmRefusing to reopen boot DEX '/system/framework/hwframework.jar'��xx�(U���
对日志的一点儿解释:
I 表示是information 级别, ActiviryManger 就是在log时设置好的。可以认为是类名。 I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...}
logcat *:E : 只显示 error 和以上级别的log
logcat MyClass:I : 只显示跟MyClass 相关的内容, 最低级别是I
注意: logcat Class:I 在我的机器上(4.1 华为mate1 ) 不起作用。
解决办法1 : (在 adb shell 中操作)
$ adb shell />logcat -s "browser","webkit"
解决办法2: ( 这里是在linux console 中操作)
$ adb shell logcat | grep xxoo