android 抓完整的log的方式(包括logcat抓所有非内核log)
2013-08-03 11:23
1246 查看
log 分为 kernel , main, events ,radio 几种log
kernel属于 linux内核的log ,通过读取 /proc/kmsg 或者通过串口来抓取。
USB连接手机抓取方式:
adb shell cat /proc/kmsg > kernel.log
串口抓取方式:
在串口终端中设置对应的串口波特率,打开相应的串口。获取log。
main, events ,radio 是 framework的log ,包括cpp 和 java代码的log。
radio 可以抓ril层的log, 抓取方式:
adb logcat -b radio -v time > radio.txt
-v time 表示在log中加入每条log发生的时间。
main log 和我们从DDMS中看到的log是一致的。
抓取方式:
adb logcat -b main -v time > main.txt
event log 属于system log
抓取方式:
adb logcat -b events -v time > events.log
其实我们不知道,logcat -b的 选项是可以复用的!第一次发现这个,我是从logcat 实现的源码中发现的。
请看下面的show_help 函数中的 红色字体。 The default is -b main -b system ,意思是说,如果我们不加 -b 选项的话,默认就是 -b main -b system 两种log。
这样我们要抓 所有的 非内核的log 就变得比较方便的。那么我们只需要把所有的四种类型的log 都加进 -b 选项中。
那么我们就可以打印所有的log啦!如下命令即可实现:
adb logcat
-b main -b system -b radio -b events -v time > all_user.log
并且,我们也可以对比 radio 和events 等各种类型的log,因为有个 时间标签,我们可以知道 不同类型的log之间的顺序。
这样子,我们就不用去开两个终端去分别抓取不同类型的log了。是不是很爽!?
#ls /dev/log/
events
ksystem
main
radio
system
事实上,我还发现了 /dev/log/ 目录下 另外还有一个很多资料当中没有提到过的 ksystem 的 设备节点。这个可能是用于获取其它信息的。目前我还没有去研究,这个设备节点是用来干什么的。如果有人知道,请告知。谢谢。
"system/core/include/cutils/logger.h"
#define LOGGER_LOG_MAIN "log/main"
#define LOGGER_LOG_RADIO "log/radio"
#define LOGGER_LOG_EVENTS "log/events"
#define LOGGER_LOG_SYSTEM "log/system"
"system/core/logcat/logcat.cpp"
static void show_help(const char *cmd)
{
fprintf(stderr,"Usage: %s [options] [filterspecs]\n", cmd);
fprintf(stderr, "options include:\n"
" -s Set default filter to silent.\n"
" Like specifying filterspec '*:s'\n"
" -f <filename> Log to file. Default to stdout\n"
" -r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f\n"
" -n <count> Sets max number of rotated logs to <count>, default 4\n"
" -v <format> Sets the log print format, where <format> is one of:\n\n"
" brief process tag thread raw time threadtime long\n\n"
" -c clear (flush) the entire log and exit\n"
" -d dump the log and then exit (don't block)\n"
" -t <count> print only the most recent <count> lines (implies -d)\n"
" -g get the size of the log's ring buffer and exit\n"
" -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio'\n"
" or 'events'. Multiple -b parameters are allowed and the\n"
" results are interleaved. The default is -b main -b system.\n"
" -B output the log in binary");
fprintf(stderr,"\nfilterspecs are a series of \n"
" <tag>[:priority]\n\n"
"where <tag> is a log component tag (or * for all) and priority is:\n"
" V Verbose\n"
" D Debug\n"
" I Info\n"
" W Warn\n"
" E Error\n"
" F Fatal\n"
" S Silent (supress all output)\n"
"\n'*' means '*:d' and <tag> by itself means <tag>:v\n"
"\nIf not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.\n"
"If no filterspec is found, filter defaults to '*:I'\n"
"\nIf not specified with -v, format is set from ANDROID_PRINTF_LOG\n"
"or defaults to \"brief\"\n\n");
}
kernel属于 linux内核的log ,通过读取 /proc/kmsg 或者通过串口来抓取。
USB连接手机抓取方式:
adb shell cat /proc/kmsg > kernel.log
串口抓取方式:
在串口终端中设置对应的串口波特率,打开相应的串口。获取log。
main, events ,radio 是 framework的log ,包括cpp 和 java代码的log。
radio 可以抓ril层的log, 抓取方式:
adb logcat -b radio -v time > radio.txt
-v time 表示在log中加入每条log发生的时间。
main log 和我们从DDMS中看到的log是一致的。
抓取方式:
adb logcat -b main -v time > main.txt
event log 属于system log
抓取方式:
adb logcat -b events -v time > events.log
其实我们不知道,logcat -b的 选项是可以复用的!第一次发现这个,我是从logcat 实现的源码中发现的。
请看下面的show_help 函数中的 红色字体。 The default is -b main -b system ,意思是说,如果我们不加 -b 选项的话,默认就是 -b main -b system 两种log。
这样我们要抓 所有的 非内核的log 就变得比较方便的。那么我们只需要把所有的四种类型的log 都加进 -b 选项中。
那么我们就可以打印所有的log啦!如下命令即可实现:
adb logcat
-b main -b system -b radio -b events -v time > all_user.log
并且,我们也可以对比 radio 和events 等各种类型的log,因为有个 时间标签,我们可以知道 不同类型的log之间的顺序。
这样子,我们就不用去开两个终端去分别抓取不同类型的log了。是不是很爽!?
#ls /dev/log/
events
ksystem
main
radio
system
事实上,我还发现了 /dev/log/ 目录下 另外还有一个很多资料当中没有提到过的 ksystem 的 设备节点。这个可能是用于获取其它信息的。目前我还没有去研究,这个设备节点是用来干什么的。如果有人知道,请告知。谢谢。
"system/core/include/cutils/logger.h"
#define LOGGER_LOG_MAIN "log/main"
#define LOGGER_LOG_RADIO "log/radio"
#define LOGGER_LOG_EVENTS "log/events"
#define LOGGER_LOG_SYSTEM "log/system"
"system/core/logcat/logcat.cpp"
static void show_help(const char *cmd)
{
fprintf(stderr,"Usage: %s [options] [filterspecs]\n", cmd);
fprintf(stderr, "options include:\n"
" -s Set default filter to silent.\n"
" Like specifying filterspec '*:s'\n"
" -f <filename> Log to file. Default to stdout\n"
" -r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f\n"
" -n <count> Sets max number of rotated logs to <count>, default 4\n"
" -v <format> Sets the log print format, where <format> is one of:\n\n"
" brief process tag thread raw time threadtime long\n\n"
" -c clear (flush) the entire log and exit\n"
" -d dump the log and then exit (don't block)\n"
" -t <count> print only the most recent <count> lines (implies -d)\n"
" -g get the size of the log's ring buffer and exit\n"
" -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio'\n"
" or 'events'. Multiple -b parameters are allowed and the\n"
" results are interleaved. The default is -b main -b system.\n"
" -B output the log in binary");
fprintf(stderr,"\nfilterspecs are a series of \n"
" <tag>[:priority]\n\n"
"where <tag> is a log component tag (or * for all) and priority is:\n"
" V Verbose\n"
" D Debug\n"
" I Info\n"
" W Warn\n"
" E Error\n"
" F Fatal\n"
" S Silent (supress all output)\n"
"\n'*' means '*:d' and <tag> by itself means <tag>:v\n"
"\nIf not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.\n"
"If no filterspec is found, filter defaults to '*:I'\n"
"\nIf not specified with -v, format is set from ANDROID_PRINTF_LOG\n"
"or defaults to \"brief\"\n\n");
}
相关文章推荐
- android 抓完整的log的方式
- android软件方式模拟硬按键的功能,包括home、back等所有按键
- 以Android L读取系统所有logcat并写入文件为例分析Android 以添加系统进程的方式申请selinux的权限执行shell脚本,以及avc:dined应该怎么申请权限
- Android截屏截图方法所有方法汇总(包括Activity、View、ScrollView、ListView、RecycleView、WebView截屏截图)
- Android网络编程——https 不验证证书方式(信任所有证书)
- Android的Logcat命令详解:翻译Enabling logcat Logging
- Android开发相关——Log日志输出显示不完整以及GsonFormat
- 列出目录下所有文件包括子目录的文件路径-采用递归方式
- Android使用adb抓完整Log
- Android组件间通信机解耦——Android EventBus和Otto框架一、前言 传统的事件传递方式包括:Handler、BroadCastReceiver、Interface 回调,相比之
- adb logcat命令查看并过滤android输出log
- adb logcat命令查看并过滤android输出log
- android 以编码的方式列出来当前app所有的窗口
- 【毕业设计】基于Android的家校互动平台开发(内含完整代码和所有文档)——爱吖校推(你关注的,我们才推)
- Android 调试之 Log和LogCat的详解
- Android退出所有Activity最优雅的方式
- android中怎么获得所有应用程序的快捷方式
- Android 使用 HttpClient 进行网络通信,包括Get方式和Post方式
- android logcat 打印完整信息
- 在android中读取联系人信息的程序,包括读取联系人姓名、联系方式和邮箱等