在使用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上用上面的