1. logcat -c 清除已有log信息
2.logcat -b main 显示主缓冲区的log
logcat -b radio 显示无线缓冲区的log
logcat -b events 显示事件缓冲区的log
3.logcat -f [filename] 将log保存到指定的文件中,例如 logcat -b radio -f /data/radio.log
4.logcat -v 设置logcat输出的格式
主要有7种输出格式:
1. brief — Display priority/tag and PID of originating process (the default format).
2. process — Display PID only.
3. tag — Display the priority/tag only.
4. thread — Display process:thread and priority/tag only.
5. raw — Display the raw log message, with no other metadata fields.
6. time — Display the date, invocation time, priority/tag, and PID of the originating process.
7. long — Display all metadata fields and separate messages with a blank lines.
比较常用的是显示时间:logcat -v time &
5.logcat -g 查看缓冲区的大小
logcat -g main
logcat -g radio
logcat -g events
Log机制的一些理解:
1. 系统结构
应用程序调用应用程序框架层的Java接口(android.util.Log)来使用日志系统,这个Java接口通过JNI方法和系统运行库最终调用内核驱动程序Logger把Log写到内核空间中。
2. 关键代码及理解
一. 应用程序框架层日志系统Java接口的实现
代码位置:frameworks/base/core/java/android/util/Log.java文件中,实现日志系统的Java接口:
在logcat中用
logcat ActivityManager:w
命令显示ActivityManager标签中等于或高于WARN级别的Log
其中
在整个Log接口中,最关键的地方声明了println_native本地方法,所有的Log接口都是通过调用这个本地方法来实现Log的注入。下面我们就继续分析这个本地方法println_native。