Android Debug Bridge(adb) 与 LogCat
来源:互联网 发布:手机扫描搜索不到网络 编辑:程序博客网 时间:2024/05/21 07:58
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就派上了用场.
如果在代码中或者是framework层中加入下面这行代码(红色标示)
此时如果我想看到这个日志
命令行中输入:adb logcat -s TagRecord:v
这时将只显示TAG为 TagRecord , 任何消息的日志信息. 如图
如果在应用程序中用了这段代码
此时要看到他们的日志,则在命令行中输入
adb logcat -s System.out:v
如下图所示
LogCat参明 数说 (感谢javaeye fins网友提供)
- <span style="font-size: small;">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" </span>
http://blog.sina.com.cn/s/blog_4de067e40100popb.html
- Android Debug Bridge(adb) 与 LogCat
- Android Debug Bridge(ADB)
- adb (Android Debug Bridge)
- ADB (android debug bridge)
- Android Debug Bridge(adb)
- ADB(Android debug bridge)
- Android Debug Bridge(adb)简介
- ADB (Android Debug Bridge)常用命令
- Android Debug Bridge(adb)
- adb (Android Debug Bridge) Android 调试桥
- Android adb(Android Debug Bridge)常用命令
- ADB (Android Debug Bridge) 详解 使用方法
- Android Debug Bridge(ADB)的配置
- ADB( Android Debug Bridge )的使用
- Help of ADB(Android Debug Bridge)
- android debug bridge(adb)的使用
- ADB(Android Debug Bridge)技术实现
- Android Debug Bridge(ADB)学习总结
- 关键字break
- iPhone开发笔记(2)MPMusicPlayerController和MPMediaPickerController打造如iPod功能类似的播放器
- operation not applicable
- 【Java】导出excel表格
- 环境变量path和classpath
- Android Debug Bridge(adb) 与 LogCat
- div里面有ul li时 让高度自适应的方法
- carp协议
- F2812的看门狗总结
- GDS 的Tide配置(使用spring)
- 初学.net第一天:
- JAVA传参数到底是值传递还是引用
- python for mysql
- C64+系列DSP的总结