如何查看log日志文件
答案:2 悬赏:0
解决时间 2021-12-05 00:20
- 提问者网友:小姐请专情
- 2021-12-04 05:06
如何查看log日志文件
最佳答案
- 二级知识专家网友:闲懒诗人
- 2021-12-04 05:29
查看方法:
一、在 java 与 c 语言中输出日志:
1) java 代码在程序中输出日志, 使用 android.util.log 类的以下 5 个方法:
log.v()、log.d()、log.i()、log.w()、log.e()。
分对应 verbose、debug、info、warn、error 的首字母。
例如:log.i( "类::函数名", "日期_时间_源码文件名_行号_日志信息内容" );
2) c 代码在程序中输出日志,使用 log 的 api 函数:
__android_log_write( 日志类型宏,日志标签字符串,日志令牌内容字符串 );
需要:1. android.mk 中添加 local_ldlibs := -l$(sysroot)/usr/lib -llog
2. *.c 中添加 #include
3. 日志类型宏有:
复制代码 代码如下:
// android log priority values, in ascending priority order.
typedef enum android_logpriority {
android_log_unknown = 0,
// only for setminpriority()
android_log_default,
android_log_verbose,
android_log_debug,
android_log_info,
android_log_warn,
android_log_error,
android_log_fatal,
// only for setminpriority(); must be last
android_log_silent,
} android_logpriority;
二、logcat 使用方法:
usage: logcat [options] [filterspecs]
用法: logcat [选项] [过滤说明]
options include:
选项包含:
-s set default filter to silent.
like specifying filterspec '*:s'
设置默认过滤为无声的。
像指定过滤说明为 *:s ,见下面 过滤说明 部份详述
-f log to file.
default to stdout
输出日志到文件。
默认为 stdout
-r [] rotate log every kbytes.
(16 if unspecified).
requires -f
设置环形日志缓冲区的kbytes。
默认值为16。
需要和 -f 选项一起使用
-n sets max number of rotated logs to , default 4
设置环形日志缓冲区的最大数目,默认值是4,需要和 -r 选项一起使用
-v sets the log print format, where is one of:
设置 log 的打印格式, 格式有如下主要7种:(不能组合使用)
brief
process
tag
thread
raw
time
threadtime
long
-c clear (flush) the entire log and exit
清除所有 log 并退出
-d dump the log and then exit (don't block)
得到所有log并退出且不阻塞
-t print only the most recent lines (implies -d)
仅打印最近的由参数 count 指出的行数(必然包含 -d)
-g get the size of the log's ring buffer and exit
得到环形缓冲区的大小并退出
-b request alternate ring buffer, 'main', 'system', 'radio' or 'events'.
multiple -b parameters are allowed and the results are interleaved.
the default is -b main -b system.
请求供替换的环形缓冲区,如:main,system,radio,events。
多个 -b 参数是被允许,并且结果是交错输出的。
-b main -b system 是默认的。
-b output the log in binary
输出 log 到二进制文件中。
filterspecs are a series of[:priority]
过滤说明是一系列[:priority]
where is a log component tag (or * for all) and priority is:
tag 是 eclipse 中 logcat 图形界面中 tag 的内容(或者有 * 表示全部),它之后的冒号(:)后面跟优先级:
日志类型标识符(优先级由低到高排列):
1. v — verbose 详细的 <- 最低优先权
2. d — debug 调试
3. i — info 消息
4. w — warn 警告
5. e — error 错误
6. f — fatal 致命的
7. s — silent 无声的 <- 最高优先权
'*' means '*:d' and by itself means :v
* 意味着 *:d 且 单孤地 tag 意味着 tag:v
if not specified on the commandline, filterspec is set from android_log_tags.
如果在命令行上没有详细说明,过滤规格即是 android_log_tags 结果集。
if no filterspec is found, filter defaults to '*:i'
如果没有过滤说明,过滤规格默认为 *:i
if not specified with -v, format is set from android_printf_log or defaults to "brief"
如果没有 -v 指定格式,将是 android_printf_log 或 brief 格式集。
1) 只输出指定 标签 和 类型 的日志
格式:
adb logcat <日志标签>:<日志类型标识符> <日志标签>:<日志类型标识符> ... *:s
注:1. 可以写多个 <日志标签>:<日志类型标识符> 之间用空格分隔;
2. 最后必须是 *:s ,表示其它的都不要显示出来
例如:
$ adb logcat dalvikvm:d checkin:w *:s
注:adb logcat checkin *:s =等同于=> adb logcat checkin:v *:s
注:以上命令均没加 -v 来指出日志格式,即默认为: android_printf_log 或 brief 格式集。
2) 输出指定 标签 和 类型 的带有格式的日志
注:以下测试日志内容为:test log format,
即 eclipse 中的 logcat 图形界面里的 text 中的内容!
1. brief - 日志类型/日志标签(进程id): 日志内容
例如:$ adb logcat -v brief checkin *:s
i/checkin(24713): test log format
2. process - 日志类型(进程id) 日志内容 (日志标签)
例如:$ adb logcat -v process checkin *:s
i(24713) test log format (checkin)
3. tag - 日志类型/日志标签: 日志内容
例如:$ adb logcat -v tag checkin *:s
i/checkin: test log format
4. thread - 日志类型(进程id:线程id)
例如:$ adb logcat -v thread checkin *:s
i(24713:0x6089) test log format
5. raw - 日志内容
例如:$ adb logcat -v raw checkin *:s
test log format
6. time - 日期 调用时间 日志类型/日志标签(进程id): 日志内容
例如:$ adb logcat -v time checkin *:s
05-27 11:25:33.854 i/checkin(24713): test log format
7. threadtime - 日期 调用时间 进程id 线程id 日志类型 日志标签: 日志内容
例如:$ adb logcat -v time checkin *:s
05-27 11:25:33.854 24713 24713 i checkin: test log format
注:只有此种格式时 线程id 为十进制数。
8. long - [ 日期 调用时间 进程id:线程id 日志类型/日志标签 ] 转行显示 日志内容
例如:$ adb logcat -v long checkin *:s
[ 05-27 11:25:33.854 24713:0x6089 i/checkin ]
test log format
一、在 java 与 c 语言中输出日志:
1) java 代码在程序中输出日志, 使用 android.util.log 类的以下 5 个方法:
log.v()、log.d()、log.i()、log.w()、log.e()。
分对应 verbose、debug、info、warn、error 的首字母。
例如:log.i( "类::函数名", "日期_时间_源码文件名_行号_日志信息内容" );
2) c 代码在程序中输出日志,使用 log 的 api 函数:
__android_log_write( 日志类型宏,日志标签字符串,日志令牌内容字符串 );
需要:1. android.mk 中添加 local_ldlibs := -l$(sysroot)/usr/lib -llog
2. *.c 中添加 #include
3. 日志类型宏有:
复制代码 代码如下:
// android log priority values, in ascending priority order.
typedef enum android_logpriority {
android_log_unknown = 0,
// only for setminpriority()
android_log_default,
android_log_verbose,
android_log_debug,
android_log_info,
android_log_warn,
android_log_error,
android_log_fatal,
// only for setminpriority(); must be last
android_log_silent,
} android_logpriority;
二、logcat 使用方法:
usage: logcat [options] [filterspecs]
用法: logcat [选项] [过滤说明]
options include:
选项包含:
-s set default filter to silent.
like specifying filterspec '*:s'
设置默认过滤为无声的。
像指定过滤说明为 *:s ,见下面 过滤说明 部份详述
-f
default to stdout
输出日志到文件。
默认为 stdout
-r [
(16 if unspecified).
requires -f
设置环形日志缓冲区的kbytes。
默认值为16。
需要和 -f 选项一起使用
-n
设置环形日志缓冲区的最大数目,默认值是4,需要和 -r 选项一起使用
-v
设置 log 的打印格式, 格式有如下主要7种:(不能组合使用)
brief
process
tag
thread
raw
time
threadtime
long
-c clear (flush) the entire log and exit
清除所有 log 并退出
-d dump the log and then exit (don't block)
得到所有log并退出且不阻塞
-t
仅打印最近的由参数 count 指出的行数(必然包含 -d)
-g get the size of the log's ring buffer and exit
得到环形缓冲区的大小并退出
-b
multiple -b parameters are allowed and the results are interleaved.
the default is -b main -b system.
请求供替换的环形缓冲区,如:main,system,radio,events。
多个 -b 参数是被允许,并且结果是交错输出的。
-b main -b system 是默认的。
-b output the log in binary
输出 log 到二进制文件中。
filterspecs are a series of
过滤说明是一系列
where
tag 是 eclipse 中 logcat 图形界面中 tag 的内容(或者有 * 表示全部),它之后的冒号(:)后面跟优先级:
日志类型标识符(优先级由低到高排列):
1. v — verbose 详细的 <- 最低优先权
2. d — debug 调试
3. i — info 消息
4. w — warn 警告
5. e — error 错误
6. f — fatal 致命的
7. s — silent 无声的 <- 最高优先权
'*' means '*:d' and
* 意味着 *:d 且 单孤地 tag 意味着 tag:v
if not specified on the commandline, filterspec is set from android_log_tags.
如果在命令行上没有详细说明,过滤规格即是 android_log_tags 结果集。
if no filterspec is found, filter defaults to '*:i'
如果没有过滤说明,过滤规格默认为 *:i
if not specified with -v, format is set from android_printf_log or defaults to "brief"
如果没有 -v 指定格式,将是 android_printf_log 或 brief 格式集。
1) 只输出指定 标签 和 类型 的日志
格式:
adb logcat <日志标签>:<日志类型标识符> <日志标签>:<日志类型标识符> ... *:s
注:1. 可以写多个 <日志标签>:<日志类型标识符> 之间用空格分隔;
2. 最后必须是 *:s ,表示其它的都不要显示出来
例如:
$ adb logcat dalvikvm:d checkin:w *:s
注:adb logcat checkin *:s =等同于=> adb logcat checkin:v *:s
注:以上命令均没加 -v 来指出日志格式,即默认为: android_printf_log 或 brief 格式集。
2) 输出指定 标签 和 类型 的带有格式的日志
注:以下测试日志内容为:test log format,
即 eclipse 中的 logcat 图形界面里的 text 中的内容!
1. brief - 日志类型/日志标签(进程id): 日志内容
例如:$ adb logcat -v brief checkin *:s
i/checkin(24713): test log format
2. process - 日志类型(进程id) 日志内容 (日志标签)
例如:$ adb logcat -v process checkin *:s
i(24713) test log format (checkin)
3. tag - 日志类型/日志标签: 日志内容
例如:$ adb logcat -v tag checkin *:s
i/checkin: test log format
4. thread - 日志类型(进程id:线程id)
例如:$ adb logcat -v thread checkin *:s
i(24713:0x6089) test log format
5. raw - 日志内容
例如:$ adb logcat -v raw checkin *:s
test log format
6. time - 日期 调用时间 日志类型/日志标签(进程id): 日志内容
例如:$ adb logcat -v time checkin *:s
05-27 11:25:33.854 i/checkin(24713): test log format
7. threadtime - 日期 调用时间 进程id 线程id 日志类型 日志标签: 日志内容
例如:$ adb logcat -v time checkin *:s
05-27 11:25:33.854 24713 24713 i checkin: test log format
注:只有此种格式时 线程id 为十进制数。
8. long - [ 日期 调用时间 进程id:线程id 日志类型/日志标签 ] 转行显示 日志内容
例如:$ adb logcat -v long checkin *:s
[ 05-27 11:25:33.854 24713:0x6089 i/checkin ]
test log format
全部回答
- 1楼网友:如果这是命
- 2021-12-04 06:03
查看方法: 一、在 Java 与 C 语言中输出日志:
1) Java 代码在程序中输出日志, 使用 android.util.Log 类的以下 5 个方法:
Log.v()、Log.d()、Log.i()、Log.w()、Log.e()。
分对应 Verbose、Debug、INFO、Warn、Error 的首字母。
例如:Log.i( "类::函数名", "日期_时间_源码文件名_行号_日志信息内容" );
2) C 代码在程序中输出日志,使用 log 的 API 函数:
__android_log_write( 日志类型宏,日志标签字符串,日志令牌内容字符串 );
需要:1. Android.mk 中添加 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
2. *.c 中添加 #include <android/log.h>
3. 日志类型宏有:
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |