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

更多相关文章

  1. 国内一些优秀Android 开发者信息
  2. Android Wifi模块相关常量定义.
  3. android小程序 查询电话号码信息
  4. android 获取信息和安装Apk
  5. [zt]获取android联系人信息
  6. Android学习笔记(四七):Content Provider初谈和Android联系人信息
  7. Android原生方式获取经纬度和城市信息
  8. 将androd项目作为moudle引入配置信息
  9. Android调用内置的无线信息隐藏菜单[转]【待验证】

随机推荐

  1. android UI系列 - 自定义4.0风格多功能对
  2. Nexus S Android 2.3.6 升级开始,将修正语
  3. 《金融时报》:谷歌正游说美商务部永久解除
  4. Android 性能优化——通过线程提高性能
  5. [新书]《Android和PHP开发最佳实践》
  6. [Android] [Android的视窗系统及显示机制
  7. Android 入门eclipse+ADT配置,bug处理及附
  8. Android layout 优化:使用include和merge
  9. 从初学android到选择每天收入50块,收入还
  10. 那些年我们用过的显示性能指标