ADB 常用命令说明
下面的过滤语句指显示优先级为warning或更高的日志信息:
adb logcat *:W
如果你电脑上运行logcat ,相比在远程adbshell端,你还可以为环境变量ANDROID_LOG_TAGS :输入一个参数来设置默认的过滤
export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"
需要注意的是ANDROID_LOG_TAGS 过滤器如果通过远程shell运行logcat 或用adb shell logcat 来运行模拟器/设备不能输出日志.
控制日志输出格式
日志信息包括了许多元数据域包括标签和优先级。可以修改日志的输出格式,所以可以显示出特定的元数据域。可以通过 -v 选项得到格式化输出日志的相关信息.
brief — Display priority/tag and PID of originating process (the default format). process — Display PID only.
tag — Display the priority/tag only.
thread — Display process:thread and priority/tag only.
raw — Display the raw log message, with no other metadata fields.
time — Display the date, invocation time, priority/tag, and PID of the originating process. long — Display all metadata fields and separate messages with a blank lines.
当启动了logcat ,你可以通过-v 选项来指定输出格式:
[adb] logcat [-v <format>]
下面是用 thread 来产生的日志格式:
adb logcat -v thread
需要注意的是你只能-v 选项来规定输出格式 option.
查看可用日志缓冲区
Android日志系统有循环缓冲区,并不是所有的日志系统都有默认循环缓冲区。为了得到日志信息,你需要通过-b 选项来启动logcat 。如果要使用循环缓冲区,你需要查看剩余的循环缓冲期:
radio — 查看缓冲区的相关的信息. events — 查看和事件相关的的缓冲区. main — 查看主要的日志缓冲区
-b 选项使用方法:
[adb] logcat [-b <buffer>]
下面的例子表示怎么查看日志缓冲区包含radio 和 telephony信息:
adb logcat -b radio

