使用 ADB LogCat 查看在Android真机上 Unity debug.log 输出日志
在使用unity开的过程中查看输出日志是避免不了的,但是在真机上遇到卡死或者尤其是闪退的时候怎么办呢?这里给大家介绍一个简单便捷的android真机查看日志方法
参考了以下3位作者的文章:
- http://blog.csdn.net/tumuzhuanjia/article/details/39555445
- http://m.blog.csdn.net/wolf96/article/details/75042938
- http://www.miui.com/article-272-1.html
在使用工具之前需要配置相应的环境变量,没有配置的同学请看
Unity SDK JDK 环境配置 避免各种莫名其妙的报错
配合之前Unity Debug输出到屏幕并保存到本地服用效果更佳,早日和顽固Bug说ByeBye
首先在WIN键+R快捷键调出运行控制台,输入cmd
在命令行中输入 adb logcat --help 命令, 就可以显示该命令的帮助信息;
Usage: logcat [options] [filterspecs] options include: -s Set default filter to silent. Equivalent to filterspec '*:S' -f <file>, --file=<file> Log to file. Default is stdout -r <kbytes>, --rotate-kbytes=<kbytes> Rotate log every kbytes. Requires -f option -n <count>, --rotate-count=<count> Sets max number of rotated logs to <count>, default 4 --id=<id> If the signature id for logging to file changes, then clear the fileset and continue -v <format>, --format=<format> Sets log print format verb and adverbs, where <format> is: brief help long process raw tag thread threadtime time and individually flagged modifying adverbs can be added: color descriptive epoch monotonic printable uid usec UTC year zone Multiple -v parameters or comma separated list of format and format modifiers are allowed. -D, --dividers Print dividers between each log buffer -c, --clear Clear (flush) the entire log and exit if Log to File specified, clear fileset instead -d Dump the log and then exit (don't block) -e <expr>, --regex=<expr> Only print lines where the log message matches <expr> where <expr> is a regular expression -m <count>, --max-count=<count> Quit after printing <count> lines. This is meant to be paired with --regex, but will work on its own. --print Paired with --regex and --max-count to let content bypass regex filter but still stop at number of matches. -t <count> Print only the most recent <count> lines (implies -d) -t '<time>' Print most recent lines since specified time (implies -d) -T <count> Print only the most recent <count> lines (does not imply -d) -T '<time>' Print most recent lines since specified time (not imply -d) count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...' 'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format -g, --buffer-size Get the size of the ring buffer. -G <size>, --buffer-size=<size> Set size of log ring buffer, may suffix with K or M. -L, --last Dump logs from prior to last reboot -b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main', 'system', 'radio', 'events', 'crash', 'default' or 'all'. Multiple -b parameters or comma separated list of buffers are allowed. Buffers interleaved. Default -b main,system,crash. -B, --binary Output the log in binary. -S, --statistics Output statistics. -p, --prune Print prune white and ~black list. Service is specified as UID, UID/PID or /PID. Weighed for quicker pruning if prefix with ~, otherwise weighed for longevity if unadorned. All other pruning activity is oldest first. Special case ~! represents an automatic quicker pruning for the noisiest UID as determined by the current statistics. -P '<list> ...', --prune='<list> ...' Set prune white and ~black list, using same format as listed above. Must be quoted. --pid=<pid> Only prints logs from the given pid. --wrap Sleep for 2 hours or when buffer about to wrap whichever comes first. Improves efficiency of polling by providing an about-to-wrap wakeup. filterspecs are a series of <tag>[:priority] where <tag> is a log component tag (or * for all) and priority is: V Verbose (default for <tag>) D Debug (default for '*') I Info W Warn E Error F Fatal S Silent (suppress all output) '*' by itself means '*:D' and <tag> by itself means <tag>:V. If no '*' filterspec or -s on command line, all filter defaults to '*:V'. eg: '*:S <tag>' prints only <tag>, '<tag>:S' suppresses all <tag> log messages. If not specified on the command line, filterspec is set from ANDROID_LOG_TAGS. If not specified with -v on command line, format is set from ANDROID_PRINTF_LOG or defaults to "threadtime"
控制台窗口输入指令格式为:[adb] logcat [<option>] ... [<filter-spec>] ...
其中的 [<option>] 的指令都有:
- "-s"选项 : 设置输出日志的标签, 只显示该标签的日志;
- "-f"选项 : 将日志输出到文件, 默认输出到标准输出流中, -f 参数执行不成功;
- "-r"选项 : 按照每千字节输出日志, 需要 -f 参数, 不过这个命令没有执行成功;
- "-n"选项 : 设置日志输出的最大数目, 需要 -r 参数, 这个执行 感觉 跟 adb logcat 效果一样;
- "-v"选项 : 设置日志的输出格式, 注意只能设置一项;
- "-c"选项 : 清空所有的日志缓存信息;
- "-d"选项 : 将缓存的日志输出到屏幕上, 并且不会阻塞;
- "-t"选项 : 输出最近的几行日志, 输出完退出, 不阻塞;
- "-g"选项 : 查看日志缓冲区信息;
- "-b"选项 : 加载一个日志缓冲区, 默认是 main, 下面详解;
- "-B"选项 : 以二进制形式输出日志;
在[<option>]后面接着的是[<filter-spec>],意思输出相应的标签内容,例如我们要查看unity的Log信息,我们就输 adb logcat -s Unity只查看unity的信息 中文显示为乱码 如果只输入adb logcat 会打印android中的所有信息,对一些不是unity内部出现的报错定位也是很有帮助的
这样输出后就算闪退我们也不怕了,但是新的问题来了,这个窗口不方便查看,而且中文还是乱码,那怎么办呢? 接着我们按照[adb] logcat [<option>] ... [<filter-spec>] ...这个格式输入 adb logcat -s Unity -d > C:\UnityDrictory\UnityADBLog.txt
输出日志信息到文件 : "-f"选项 : 该选向后面跟着输入日志的文件, 使用adb logcat -f /sdcard/log.txt 命令, 注意这个log文件是输出到手机上,需要指定合适的路径。PC上用上面的
这样我们就可以以文本的方式查看Log日志了,而且中文不再是乱码
根据[<option>]选项中的 -f 的说明:默认输出到标准输出流中,所以在查看下次运行的日志时候,需要提前清空日志缓存 adb logcat -c ,这样就不会把上次不用的日志打印出来了
而且配合Notepad++查看txt就更方便了,它会自动格几秒提醒你是否要更新文本,更新了就获取到了最新的打印日志
Notepad++下载地址

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Android 调试工具集合
Vysor 提供Windows、Mac、Linux和chrome插件,在电脑屏幕上可操作手机. Robolectric 可以在test文件夹下直接操作Android中的UI控件,方便调试。推荐文章Android单元测试框架Robolectric3.0介绍 Android-Debug-Database 可在浏览器中查看手机应用的数据库文件 Espresso 自动化测试,创建项目时已导入相对应的包。
- 下一篇
HDU1012 Calculate e
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1012 解法一:最直观的方法,就是递归计算来求各项之和 #include <iostream> #include <iomanip> using namespace std; double curItem(int n) {//当前子项 if (n==0) { return 1; } else return curItem(n-1)/n; } double sum(int n) { if(n==0) return 1; else return sum(n-1)+curItem(n); } void caculateE(int n) {//输出指定n下e的值 double tmp1,tmp2=1.0f,result=0.0f; int i; result = sum(n); if(n==0||n==1) { cout<<n<<" "<<static_ca...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS8编译安装MySQL8.0.19
- CentOS7,CentOS8安装Elasticsearch6.8.6
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- Red5直播服务器,属于Java语言的直播服务器
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- SpringBoot2整合Thymeleaf,官方推荐html解决方案