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"  

更多相关文章

  1. Android6.0修改设备设置中kernel信息
  2. Android之获取sdcard卡的信息
  3. 自动搜索私密信息与彻底删除APP--(一)清理
  4. Android系统信息获取 之十二:获取屏幕分辨率及密度
  5. 获取Android设备硬件信息
  6. Android 获取手机存储信息详解(内存,外存等)
  7. Android系统信息获取 之十四:获取WIFI热点相关信息

随机推荐

  1. Android开发心得(一)
  2. Android软键盘弹出时布局的调整问题
  3. Android神技之 使用SVG以及自定义IconFon
  4. Material Design(六)
  5. Android中图表AChartEngine学习使用与例
  6. Android开发者的福音-良心之选
  7. Android通过WebView实现原生Java与JS交互
  8. Android(安卓)低功耗(BLE)蓝牙(三)
  9. H5跟ios、android数据对接
  10. Android--控件Button的详细用法介绍(适合