查看方法:
一、在 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. 日志类型宏有:
复制代码 代码如下:
// 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 <filename> Log to file.
Default to stdout
输出日志到文件。
默认为 stdout
-r [<kbytes>] Rotate log every kbytes.
(16 if unspecified).
Requires -f
设置环形日志缓冲区的kbytes。
默认值为16。
需要和 -f 选项一起使用
查看方法:
一、在 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. 日志类型宏有:
复制代码 代码如下:
// 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 <filename> Log to file.
Default to stdout
输出日志到文件。
默认为 stdout
-r [<kbytes>] Rotate log every kbytes.
(16 if unspecified).
Requires -f
设置环形日志缓冲区的kbytes。
默认值为16。
需要和 -f 选项一起使用
-n <count> Sets max number of rotated logs to <count>, default 4
设置环形日志缓冲区的最大数目,默认值是4,需要和 -r 选项一起使用
-v <format> Sets the log print format, where <format> 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 <count> print only the most recent <count> lines (implies -d)
仅打印最近的由参数 count 指出的行数(必然包含 -d)
-g get the size of the log"s ring buffer and exit
得到环形缓冲区的大小并退出
-b <buffer> 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 <tag>[:priority]
过滤说明是一系列 <tag>[:priority]
where <tag> is a log component tag (or * for all) and priority is:
tag 是 eclipse 中 logcat 图形界面