摸鱼笔记-ADB-日志查看、抓取

时间:2025-04-06 07:25:03

查日志抓日志这块搞安卓测试一定要玩的明白才行,分析日志会不会无所谓,至少不能在APP(游戏)出了问题后直接拎着设备就去找程序哥哥了????????,如果程序带哥儿很难忙,你不是特别“美”,而且一会来一趟的话,可能会被锤????????????

抓取日志

格式:

adb logcat -选项  筛选条件
  • 1

选项有以下几种:

选项 含义
v 设置输出格式的日志消息。默认是短暂的格式。更多格式下边细说
c 清除缓冲区中的全部日志并退出(清除完后可以使用-g查看缓冲区)
g 打印日志缓冲区的大小并退出
b 加载一个可使用的日志缓冲区供查看
d 将缓冲区的log转存到屏幕中然后退出
s 设置过滤器
t 输出最近的几行日志, 输出完退出
f 将log输出到指定的文件中(手机的文件夹)
r 没时输出日志,默认值是16,需要和-f选项一起使用
n 设置日志的最大数目,默认值是4,需要和-r选项一起使用
B 以二进制形式输出日志

以上经常用到的也就-c -v。????????????
一般把日志导出到电脑上使用以下命令:

adb logcat >E:\
#按ctrl+C停止
  • 1
  • 2

—————————————————————————————————————
日志的过滤级别:

  • V—— Verbose(最低一级,全部)
  • D—— Debug
  • I—— Info
  • W—— Warning
  • E—— Error
  • F—— Fatal
  • S—— Silent(最高一级,啥也没有)

按某级别过滤日志则会将该级别及以上的日志输出。
例如:

adb logcat *:e
#输出Error、Fatal、Silent级别的日志

#按照标签过滤日志
adb logcat :w :f *:s
#输出discord的Warning级与xiaotangguo的 Fatal级与其他应用Silent级的日志(*:s相当于屏蔽掉其他应用的日志)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

可以用 adb logcat -v <格式> 选项指定日志输出格式。
brief

adb logcat -v brief
#日志格式如下:
<priority>/<tag>(<pid>): <message>
#例如:
I/personalized( 9022): [eSer]    pullPersonalLocked, pull failed, retry after 15s...
D/personalized( 9022): [eSer]   stopSelfDelayed, startId: 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

process

adb logcat -v process
#日志格式如下:
<priority>(<pid>) <message>
例如:
E/LePush  ( 4869):      at (:818)
I/LePush  ( 4869): Request ip address fail! Will request again after 300s later.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

tag

adb logcat -v tag
#日志格式如下:
<priority>/<tag>: <message>
例如:
I/chatty  : uid=1036(auditd) expire 1 line
I/FeedbackManager: postGenerateRequest: mEventList size is 0
E/ThermalEngine: Can't find property .qti_case!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

raw

adb logcat -v raw
#日志格式如下:
<message>
例如:
Loading bound service for intent: Intent { act= FromType=0xffffffff mCallingUid=10134 cmp=/. }
Task / started execution. cause:14 exec_start_elapsed_seconds: 436777 [CONTEXT service_id=218 ]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

time

adb logcat -v time
#日志格式如下:
<datetime> <priority>/<tag>(<pid>): <message>
例如:
04-06 18:15:32.069 V/NotificationService( 1337): notifications are disabled by AppOps for 
04-06 18:15:32.069 E/NotificationService( 1337): Suppressing notification from package  by user request.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

threadtime

adb logcat -v threadtime
#日志格式如下:
<datetime> <pid> <tid> <priority> <tag>: <message>
例如:
04-06 18:39:18.841 18199 18437 E Phone_Manager: [testRed] showNoti 1 addphoneIntercept = 0;addmmsIntercept = 2
04-06 18:39:18.847  1337  1337 V NotificationService: notifications are disabled by AppOps for 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

long

adb logcat -v long
#日志格式如下:
[ <datetime> <pid>:<tid> <priority>/<tag> ]
<message>
例如:
[ 04-06 18:39:14.847  1337: 1337 V/NotificationService ]
notifications are disabled by AppOps for 

[ 04-06 18:39:14.847  1337: 1337 E/NotificationService ]
Suppressing notification from package  by user request.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

正常导出日志就使用logcat -v time就行,如果有其他需求可以使用其他的日志格式。
指定格式可与上面的过滤同时使用。比如:

adb logcat -v long :w *:S
  • 1

清空日志:

adb logcat -c
  • 1

内核日志:

adb shell dmesg
#例如:
0[69333.944925][2021-04-07 06:24:27.743656559]PM: suspend exit 2021-04-07 05:12:23.691604967 UTC
0[69334.045174][2021-04-07 06:24:27.743662236]PM: suspend entry 2021-04-07 05:12:23.791850123 UTC
0[69334.045191][2021-04-07 06:24:27.743667705]PM: Syncing filesystems ... done.
  • 1
  • 2
  • 3
  • 4
  • 5

内核日志这块是完全没有用过,太细节的东西不太了解了????‍♂️????‍♂️????‍♂️