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

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

在使用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
相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
相关文章
|
9月前
|
开发工具 Android开发
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
890 11
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
|
Shell Linux 开发工具
"开发者的救星:揭秘如何用adb神器征服Android设备,开启高效调试之旅!"
【8月更文挑战第20天】Android Debug Bridge (adb) 是 Android 开发者必备工具,用于实现计算机与 Android 设备间通讯,执行调试及命令操作。adb 提供了丰富的命令行接口,覆盖从基础设备管理到复杂系统操作的需求。本文详细介绍 adb 的安装配置流程,并列举实用命令示例,包括设备连接管理、应用安装调试、文件系统访问等基础功能,以及端口转发、日志查看等高级技巧。此外,还提供了常见问题的故障排除指南,帮助开发者快速解决问题。掌握 adb 将极大提升 Android 开发效率,助力项目顺利推进。
804 0
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
10342 2
|
图形学 Android开发 iOS开发
穿越数字洪流,揭秘Unity3d中的视频魔法!Windows、Android和iOS如何征服RTSP与RTMP的终极指南!
【8月更文挑战第15天】在数字媒体的海洋中,实时视频流是连接世界的桥梁。对于那些渴望在Unity3d中搭建这座桥梁的开发者来说,本文将揭示如何在Windows、Android和iOS平台上征服RTSP与RTMP的秘密。我们将深入探讨这两种协议的特性,以及在不同平台上实现流畅播放的技巧。无论你是追求稳定性的RTSP拥趸,还是低延迟的RTMP忠实粉丝,这里都有你需要的答案。让我们一起穿越数字洪流,探索Unity3d中视频魔法的世界吧!
587 2
|
Java 网络安全 开发工具
UNITY与安卓⭐一、Android Studio初始设置
UNITY与安卓⭐一、Android Studio初始设置
|
图形学 Android开发
小功能⭐️Unity调用Android常用事件
小功能⭐️Unity调用Android常用事件
|
图形学 iOS开发 Android开发
从Unity开发到移动平台制胜攻略:全面解析iOS与Android应用发布流程,助你轻松掌握跨平台发布技巧,打造爆款手游不是梦——性能优化、广告集成与内购设置全包含
【8月更文挑战第31天】本书详细介绍了如何在Unity中设置项目以适应移动设备,涵盖性能优化、集成广告及内购功能等关键步骤。通过具体示例和代码片段,指导读者完成iOS和Android应用的打包与发布,确保应用顺利上线并获得成功。无论是性能调整还是平台特定的操作,本书均提供了全面的解决方案。
898 0
|
Shell 开发工具 Android开发
|
Shell Android开发
Android系统 adb shell push/pull 禁止特定文件
Android系统 adb shell push/pull 禁止特定文件
1852 1
|
Android开发 Python
Python封装ADB获取Android设备wifi地址的方法
Python封装ADB获取Android设备wifi地址的方法
619 0