log 分為 kernel ,
main, events ,radio 幾種log
kernel屬於 linux內核的log ,通過讀取
/proc/kmsg 或者通過串口來抓取。
USB連接手機抓取方式:
adb shell cat /proc/kmsg > kernel.log
串口抓取方式:
在串口終端中設置對應的串口串列傳輸速率,打開相應的串口。獲取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
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"
#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,"Usage: %s [options] [filterspecs]\n", cmd);
fprintf(stderr,
"options include:\n"
" -s Set default filter to silent.\n"
" Like specifying filterspec '*:s'\n"
" -f Log to file. Default to
stdout\n"
" -r [] Rotate log every kbytes. (16 if
unspecified). Requires -f\n"
" -n Sets max number of
rotated logs to , default 4\n"
" -v Sets the log print
format, where 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 print only the most
recent lines (implies -d)\n"
" -g get the size of the log's ring buffer and exit\n"
" -b 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");
" -s Set default filter to silent.\n"
" Like specifying filterspec '*:s'\n"
" -f
" -r [
" -n
" -v
" 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
" -g get the size of the log's ring buffer and exit\n"
" -b
" or 'events'. Multiple -b parameters are allowed and the\n"
" results are interleaved. The default is
" -B output the log in binary");
fprintf(stderr,"\nfilterspecs are a series of \n"
"[:priority]\n\n"
"where 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 by itself means :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");
"
"where
" 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
"\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");
}
l
Reference Link:
http://www.xuebuyuan.com/1798840.html
沒有留言:
張貼留言