您现在的位置是:首页 > 文章详情

使用 ADB LogCat 查看在Android真机上 Unity debug.log 输出日志

日期:2017-12-26点击:898

在使用unity开的过程中查看输出日志是避免不了的,但是在真机上遇到卡死或者尤其是闪退的时候怎么办呢?这里给大家介绍一个简单便捷的android真机查看日志方法

参考了以下3位作者的文章:

在使用工具之前需要配置相应的环境变量,没有配置的同学请看

Unity SDK JDK 环境配置 避免各种莫名其妙的报错

配合之前Unity Debug输出到屏幕并保存到本地服用效果更佳,早日和顽固Bug说ByeBye

首先在WIN键+R快捷键调出运行控制台,输入cmd
img_e9c58856284ab41a7025d3df529bec54.png
在命令行中输入 adb logcat --help 命令, 就可以显示该命令的帮助信息;
img_40789342b10a9e466467b09d6cd86b0a.gif
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内部出现的报错定位也是很有帮助的

img_88262199718f503b107ca2715e0153dd.gif

这样输出后就算闪退我们也不怕了,但是新的问题来了,这个窗口不方便查看,而且中文还是乱码,那怎么办呢? 接着我们按照[adb] logcat [<option>] ... [<filter-spec>] ...这个格式输入 adb logcat -s Unity -d > C:\UnityDrictory\UnityADBLog.txt

输出日志信息到文件 : "-f"选项 : 该选向后面跟着输入日志的文件, 使用adb logcat -f /sdcard/log.txt 命令, 注意这个log文件是输出到手机上,需要指定合适的路径。PC上用上面的

img_6f0acb52dbcc21ef7d24ccceeceae7ac.gif

这样我们就可以以文本的方式查看Log日志了,而且中文不再是乱码

根据[<option>]选项中的 -f 的说明:默认输出到标准输出流中,所以在查看下次运行的日志时候,需要提前清空日志缓存 adb logcat -c ,这样就不会把上次不用的日志打印出来了

img_1f29d9cce2d605e5014ba56c33d75701.gif

而且配合Notepad++查看txt就更方便了,它会自动格几秒提醒你是否要更新文本,更新了就获取到了最新的打印日志

Notepad++下载地址

img_7ee6d4444df82fc96f85b1c6c366fa08.png
原文链接:https://yq.aliyun.com/articles/666214
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章