adb 命令使用之抓取log并过滤。

开发过程中,,解决各种问题bug,不管是性能问题还是ANR问题,还是各种严重崩溃问题,经常需要抓取log,从log中分析找到问题源头,并进行修改。

但是,统一时间点下,可能会有很多log打印出来,分属于各个不同的进程。因此,我们需要的部分可能已经被淹没了。因此,使用工具或者命令抓取需要的log部分,并尽可能少的减少遗漏,是非常有必要的。

通常情况下,可以使用工具。

因此,使用命令抓取变得很重要,这里就自己总结下adb相关的命令。

比如eclipse 的logcat可以直接查看log输出,但是有个问题就是在手机设备没有连接的情况下,是很恼火的。比如我需要开机log,可以直接使用adb抓取到txt文件中就OK了。google的同时自己整理了一下。不喜勿喷。

adb logcat 命令使用帮助说明;

logcat: option requires an argument — vUnrecognized OptionUsage: logcat [options] [filterspecs]options include: -sSet default filter to silent.Like specifying filterspec '*:s' -f <filename> Log to file. Default to stdout -r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f -n <count>Sets max number of rotated logs to <count>, default 4 -v <format>Sets the log print format, where <format> is one of:brief process tag thread raw time threadtime long -cclear (flush) the entire log and exit -ddump the log and then exit (don't block) -t <count>print only the most recent <count> lines (implies -d) -gget the size of the log's ring buffer and exit -b <buffer>Request alternate ring buffer, 'main', 'system', 'radio'or 'events'. Multiple -b parameters are allowed and theresults are interleaved. The default is -b main -b system. -Boutput the log in binaryfilterspecs are a series of <tag>[:priority]where <tag> is a log component tag (or * for all) and priority is: V Verbose D Debug I Info W Warn E Error F Fatal S Silent (supress all output)'*' means '*:d' and <tag> by itself means <tag>:vIf not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.If no filterspec is found, filter defaults to '*:I'If not specified with -v, format is set from ANDROID_PRINTF_LOGor defaults to "brief"

抓取log之前先清除缓存的log信息。

appledeMacBook-Pro:~ apple$ adb logcat -c appledeMacBook-Pro:~ apple$

或者你可以这样写

appledeMacBook-Pro:~ apple$ adb logcat -c && adb logcat ——— beginning of /dev/log/mainE/cynicok (16917): receive a heartbeat msg: H!I/Wisdom_ConnectSdk(16917): request long connection success and the state = 200I/Wisdom_ConnectSdk(16917): receive the heart message H

这样查看晕死。。。。appledeMacBook-Pro:~ apple$ adb logcat ——— beginning of /dev/log/mainD/AppOps ( 1989): startOperation: allowing code 40 uid 1000 package androidD/NtpTrustedTime( 1989): currentTimeMillis() cache hit——— beginning of /dev/log/systemD/PowerManagerService( 1989): newScreenState = 0D/PowerManagerService( 1989): updateDisplayPowerStateLocked: mBootCompleted = true, mScreenBrightnessSettingDefault = 165D/PowerManagerService( 1989): updateDisplayPowerStateLocked: xxxx = 187D/PowerManagerService( 1989): Package Lib: shouldUseProximitySensorLocked mLidMode = falseD/PowerManagerService( 1989): updateDisplayPowerStateLocked: yyyyy = 187D/PowerManagerDisplayController( 1989): changed is false, mPendingRequestChangedLocked = falseD/NtpTrustedTime( 1989): currentTimeMillis() cache hitD/NtpTrustedTime( 1989): currentTimeMillis() cache hit

使用I,V,D,E,F,W等过滤

和Log.i ,Log.e ,Log.d,Log.w等对应。

appledeMacBook-Pro:~ apple$ adb logcat *:I ——— beginning of /dev/log/main——— beginning of /dev/log/systemE/cynicok (16917): receive a heartbeat msg: H!I/Wisdom_ConnectSdk(16917): request long connection success and the state = 200I/Wisdom_ConnectSdk(16917): receive the heart message HE/cynicok (16917): receive a heartbeat msg: H!I/Wisdom_ConnectSdk(16917): request long connection success and the state = 200I/Wisdom_ConnectSdk(16917): receive the heart message HE/cynicok (16917): receive a heartbeat msg: H!I/Wisdom_ConnectSdk(16917): request long connection success and the state = 200I/Wisdom_ConnectSdk(16917): receive the heart message H上面输出全部是Log.i打印出来的Log.

输出指定标签的日志.后面必须是*:S

appledeMacBook-Pro:~ apple$ adb logcat Wisdom_ConnectSdk:* *:S——— beginning of /dev/log/main——— beginning of /dev/log/systemI/Wisdom_ConnectSdk(16917): request long connection success and the state = 200打印有时间的LogappledeMacBook-Pro:~ apple$ adb logcat -v time——— beginning of /dev/log/main02-08 12:18:48.700 D/eup(17972): rqdp{ current unseen pn:}com.tencent.androidqqmail:Push02-08 12:18:49.810 D/MSF.C.NetConnTag( 2700): [E]netRecv ssoSeq:2023997818 uin:*9889 cmd:-316037937 202399809802-08 12:18:49.840 D/Q.msg.TroopMsgProxy(18335): [E]insertToList MessageRecord=friendUin:2824senderuin:9517,istroop:1,msgType:-1000,time:1423369131,shmsgseq:3394902-08 12:18:50.630 D/MSF.C.NetConnTag( 2700): [E]netRecv ssoSeq:2024000051 uin:*9889 cmd:961141751 202400063502-08 12:18:50.665 D/MSF.C.NetConnTag( 2700): [E]pa ok: 9323902-08 12:18:50.670 D/MSF.C.NetConnTag( 2700): [E]netSend ssoSeq:93239 uin:*9889 cmd:-183665717 93419——— beginning of /dev/log/system

-v 设置log的打印格式。上面的time显示时间。

旅游时最好的习惯:找个舒适的小店,挑张雅致的明信片,

adb 命令使用之抓取log并过滤。

相关文章:

你感兴趣的文章:

标签云: