如何 open/view iOS OSLogs 存储在设备上?

How can I open/view iOS OSLogs stored on device?

我正在使用 Apple 的 os.log 框架创建日志。我只是在制作日志:

os_log("Update: Lat: %{public}f | Long:  %{private}f | RemainingTime: %{public}f ", log: log, type: .default, location.coordinate.latitude, location.coordinate.longitude, UIApplication.shared.backgroundTimeRemaining).

我确实在控制台和调试器中看到了日志。

我已经阅读 this 并且我能够成功下载容器(只是不确定容器是否包含我正在寻找的内容或者这是不是应该查看的正确位置)。然后我点击 Show packages:

但在那之后我只看到:

我查看了所有文件。这些文件只包含如下数字:

我应该做些额外的事情还是找错地方了?


EDIT1: 在 JAL 的建议之后:

我查看了(文档、库、tmp)。有 plistktx 个文件。和 function.data & map.data 文件。

我查看了这些文件:

还有这些文件:

我尝试用控制台打开它们,但得到如下图所示的乱码结果:


EDIT2:

所以首先我没有权限打开 /var/db/diagnostics,我不得不打开 sudo bash。然后我做了 cd /var/db/diagnostics 并看到了这些文件。

Events
FaultsAndErrors
Oversize
SpecialHandling
StateDumps
TTL
logdata.Persistent.20170724T212501.tracev3
logdata.Persistent.20170725T015616.tracev3
logdata.Persistent.20170725T134017.tracev3
logdata.Persistent.20170725T171020.tracev3
logdata.Persistent.20170725T213354.tracev3
logdata.Persistent.20170726T002702.tracev3
logdata.Persistent.20170726T144412.tracev3
logdata.Persistent.20170726T202128.tracev3
logdata.Persistent.20170727T021506.tracev3
logdata.Persistent.20170727T033929.tracev3
logdata.Persistent.20170727T075325.tracev3
logdata.Persistent.20170727T145233.tracev3
logdata.statistics.0.txt
logdata.statistics.1.txt
shutdown.log

然后我做了 open -a console logdata.Persistent.20170725T015616.tracev3(我也尝试了其他 .tracev3 文件),但控制台只是打开并开始实时跟踪,就好像我只是正常打开控制台一样...

您没有在问题中指定 iOS、macOS 或 tvOS,因此我的回答在所有平台上都是通用的。

评论WWDC 2016 - Session 721 - Unified Logging and Activity Tracing

记录数据以新的压缩二进制格式(.tracev3.logarchive 文件)存储,这就是那些“数字”。您必须使用 Console.app 或 log 命令行工具打开这些文件。

您在错误的位置查找日志文件。来自 session 视频:

Those files are now stored under /var/db/diagnostics with additional supporting files in /var/db/uuidtext. There are new tools to access that data, there's a new Console, a new log command line tool and one of the things you have to keep in mind is because the data is now stored in a binary format you must use the new tools to access it. So you can no longer grep through logs you have to use our tools to do the surfing through it.

There's also another new type of file the .logarchive, which is there for portability of log data. Essentially a .logarchive is a collection of information out of /var/db/diagnostics and you uuidtext collected together into a single file that's easier to transfer to email, to attach to bug reports and the like.

如果您将 stdout 或 stderr 重定向到一个文件(例如 this example 中的代码),它应该位于应用程序沙箱的 Documents 目录中(或您指定的任何目录)。写入 /var/db/diagnostics 的日志通常对 iOS 和 tvOS 上的最终用户不可用。

选项 A:无需任何特定设置即可远程检索日志。

  • 触发一个.
  • 使用 Airdrop 并将系统诊断分享给您的 mac
  • 取消存档 sysdiagnose 文件。它看起来像这样:

  • 用Console.app
  • 打开system_logs.logarchive
  • 就好像您已连接到 Console.app。您可以按子系统、日志级别、类别和时间进行过滤。它看起来像这样:

注意:搜索和过滤速度很慢。有时需要2分钟。如果您过滤掉您不关心的 日期 可能会有所帮助。您可以使用底部的文件管理器来做到这一点。 您必须等到右下角的加载存档微调器完成加载

选项 B:将它们重定向以存储在您的应用沙盒中

按照this answer I was able to redirect the logs into the documents directory for my app's sandbox, then I was able to download my container/sandbox using this回答的建议后。

单击“显示包内容”后,我得到了这个:

我使用控制台打开日志文件,得到的结果是:

经度应该显示为 private,但自从我通过 Xcode 得到它后,即调试模式仍然呈现该字段 public.