Android中Log机制详解
来源:互联网 发布:淘宝时雨改二 编辑:程序博客网 时间:2024/05/16 04:58
Android中Log的输出有如下几种:
Log.v(String tag, String msg); //VERBOSE
Log.d(String tag, String msg); //DEBUG
Log.i(String tag, String msg); //INFO
Log.w(String tag, String msg); //WARN
Log.e(String tag, String msg); //ERROR
以上log的级别依次升高,VERBOSE DEBUG信息应当只存在于开发中,INFO,WARN,ERROR这三种log将出现在发布版本中。
对于JAVA类中,可以声明一个字符串常量TAG,Logcat可以根据他来区分不同的log,例如在WindowsManagerService.java的类中,定义如下所示:
static final Sting TAG = "WindowManager"
需要打log的地方
Log.v(TAG, "Figuring out where to add app window" + client.asBinder() + "(token=" + token + ")");
logcat使用方法如下所示:
logcat [options] [filterspecs]
option "-s" 用来设置过滤器,格式是这样的 <tag>[:priority]
其中 <tag> 表示log的component, tag (或者使用 * 表示所有) ,priority如下所示:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent
例:
logcat -s *:s 不打任何log
logcat -s WindowMnager:V <-- 打印WindowManagerService 中 Verbose 信息
如果在eclipse中查看Android log 输出,也就是logcat信息,可以 选择Windows > Show View > Other... > Android > LogCat。
附
logcat的参数说明:
Usage: logcat [options] [filterspecs]
options include:
-s Set default filter to silent.
Like specifying filterspec '*:s'
-f <filename> Log to file. Default to stdout
-r [<kbytes>] Rotate log every kbytes. (16 if unspecified). Requires -f
-n <count> Sets max number of rotated logs to <count>, default 4
-v <format> Sets the log print format, where <format> is one of:
brief process tag thread raw time long
-c clear (flush) the entire log and exit
-d dump the log and then exit (don't block)
-g get the size of the log's ring buffer and exit
-b <buffer> request alternate ring buffer, defaults to 'main'
filterspecs are a series of
<tag>[:priority]
where <tag> is a log component tag (or * for all) and priority is:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent (supress all output)
'*' means '*:d' and <tag> by itself means <tag>:v
If not specified on the commandline, filterspec is set from ANDROID_LOG_TAG
If no filterspec is found, filter defaults to '*:I'
If not specified with -v, format is set from ANDROID_PRINTF_LOG
or defaults to "brief"
转自:http://stulog.com/?post=212
- Android中Log机制详解
- Android中Log机制详解
- Android中Log机制详解
- Android中LOG机制详解
- Android中LOG机制详解(上)
- Android中LOG机制详解(下)
- Android 中 Log 机制详解(转)
- Android中LOG机制详解(下)
- Android中LOG机制详解(上)
- Android中Log机制
- android系统中log机制
- Android中Log图文详解
- 【Android】 Android中Log调试详解
- Android Log 机制
- Android LOG机制流程图
- Android LOG机制流程图
- Android LOG机制流程图
- Android的log机制
- SQLServer2005 Pivot 转置使用动态列
- 转载:android adb 总结
- Froyo 自动编译方法
- IceBox实践
- 将minicom移植到mini2440(tq2440)
- Android中Log机制详解
- 对工作的态度
- 从火车站到中国馆
- 安装iphone软件
- TestDriven.NET 2.0——单元测试的好助手
- password hashes without fgdump
- JPA 中 one-toone 一对一 映射
- 央行的主要货币政策
- 寻找高手