如何从 os_log() 中查找源文件和行号
How to find source file and line number from os_log()
iOS 10 和 macOS Sierra 中新日志系统的 Logging Apple reference 明确表示不包括行号和源文件信息,因为它是自动捕获的。
Don’t include symbolication information or source file line numbers in messages. The system automatically captures this information.
但我还没有找到任何方法来查看这些假定捕获的值。在控制台应用程序中,我可以看到子系统、类别、进程 ID 等,但没有关于文件和行的信息。
同样,命令行工具似乎缺少显示此信息的任何选项(除非我遗漏了什么)。
有人弄明白了吗?
我认为它在 Swift 中不可用,尽管您可以在终端中看到 C/C++ 中的文件和行号。请参阅 Apple 论坛 here。
我通过创建一个简单的 command-line 工具 Xcode 项目尝试了与论坛内部类似的东西:
import Foundation
import os.log
os_log("rrrr")
并在终端中输入以下内容:log stream --source --predicate 'eventMessage contains "rrrr"'
,我得到了这个:
Timestamp Thread Type Activity PID
2017-02-18 17:58:46.012381+0700 0x5067d Default 0x0 5637 <testLogSwift`_swift_os_log> rrrr
与我在 C/C++ 版本中得到的对比,它显示了文件和行号:
Timestamp Thread Type Activity PID
2017-02-18 17:55:05.056103+0700 0x4aa01 Default 0x0 5218 <testLogging`main (main.cpp:13)> qqq
iOS 10 和 macOS Sierra 中新日志系统的 Logging Apple reference 明确表示不包括行号和源文件信息,因为它是自动捕获的。
Don’t include symbolication information or source file line numbers in messages. The system automatically captures this information.
但我还没有找到任何方法来查看这些假定捕获的值。在控制台应用程序中,我可以看到子系统、类别、进程 ID 等,但没有关于文件和行的信息。
同样,命令行工具似乎缺少显示此信息的任何选项(除非我遗漏了什么)。
有人弄明白了吗?
我认为它在 Swift 中不可用,尽管您可以在终端中看到 C/C++ 中的文件和行号。请参阅 Apple 论坛 here。
我通过创建一个简单的 command-line 工具 Xcode 项目尝试了与论坛内部类似的东西:
import Foundation
import os.log
os_log("rrrr")
并在终端中输入以下内容:log stream --source --predicate 'eventMessage contains "rrrr"'
,我得到了这个:
Timestamp Thread Type Activity PID
2017-02-18 17:58:46.012381+0700 0x5067d Default 0x0 5637 <testLogSwift`_swift_os_log> rrrr
与我在 C/C++ 版本中得到的对比,它显示了文件和行号:
Timestamp Thread Type Activity PID
2017-02-18 17:55:05.056103+0700 0x4aa01 Default 0x0 5218 <testLogging`main (main.cpp:13)> qqq