`
wayfarer
  • 浏览: 294713 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android Debug Bridge(adb, Android调试桥) 与 Log

阅读更多

adb是多种用途的工具,该工具可以帮助你你管理设备或模拟器的状态。在android中,adb可以调动LogCat Show View,用来替代Console (android的后台信息显示:包括System.out.println()、e.printStackTrace()不会在console中显示,而需要在LogCat中显示)。Logcat用于观察调试内容,LogCat不支持中文,但是其过滤器功能很好用,System.out.println()是以I级别显示在LogCat中的
Log.v的调试颜色为黑色 的,任何消息都会输出;
Log.d的输出颜色是蓝色的 ,仅输出debug,但他会输出上层的信息,过滤通过DDMS的Logcat标签来选择。
Log.i的输出为绿色 ,一般提示性的消息information,它不会输出Log.v和Log.d的信息,但会显示i、w和e的信息。
Log.w的意思为橙色 ,需要我们注意优化Android代码,同时选择它后还会输出Log.e的信息。
Log.e为红色 ,这些错误就需要我们认真的分析,查看栈的信息了。


在android程序中输出日志,使用android.util.Log 类。该类提供了若干静态方法

Log.v(String tag, String msg);
Log.d(String tag, String msg);
Log.i(String tag, String msg);
Log.w(String tag, String msg);
Log.e(String tag, String msg);

分别对应 Verbose, Debug, Info, Warning, Error。其中tag是一个标识, 可以是任意字符串, 通常可以使用类名+方法名, 主要是用来在查看日志时提供一个筛选条件 。android规范建议VERBOSE,DEBUG信息应当只存在于开发中,最终版本只可以包含INFO, WARN,ERROR这三种日志信息。

日志显示命令行:adb logcat(Run As --> Run Configurations --> Target --> Additional Emulator Command Line Options)。
当执行adb logcat后会以tail方式实时显示出所有的日志信息. 这时候我们通常需要对信息进行过滤,来显示我们需要的信息,这时候我们指定的TAG就派上了用场.
命令行中输入:adb logcat -s x-navi:I
这时将只显示TAG为
x-navi , 级别为I或级别高于I(Warning,Error)的日志信息.


LogCat参明 数说 (感谢javaeye fins网友提供)

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"  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics