如何从 os_log() 中查找源文件和行号 [英] How to find source file and line number from os_log()

查看:65
本文介绍了如何从 os_log() 中查找源文件和行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于iOS 10和macOS中新日志记录系统的记录Apple参考Sierra明确表示不包括行号和源文件信息,因为它会自动捕获.

The Logging Apple reference for the new logging system in iOS 10 and macOS Sierra explicitly say not to include line number and source file info, because it is automatically captured.

不要在消息中包含符号信息或源文件行号.系统会自动捕获此信息.

Don’t include symbolication information or source file line numbers in messages. The system automatically captures this information.

但是我还没有找到查看这些所谓捕获值的任何方法.在控制台应用程序中,我可以看到子系统,类别,进程ID等,但看不到文件和行.

But I have yet to be able to find any way of viewing these supposedly captured values. In the Console app I can see subsystem, category, process ID, etc, but nothing about file and line.

同样,命令行工具似乎也缺少用于显示此信息的任何选项(除非我遗漏了某些内容).

And the command line tool similarly appears to lack any options for displaying this information (unless I'm missing something).

有人知道吗?

推荐答案

尽管您可以在Terminal的C/C ++中看到文件和行号,但我认为它在Swift中尚不可用.请参阅苹果论坛此处.

I don't think it's available in Swift yet, although you can see file and line number in C / C++ in Terminal. See Apple forum here.

我通过创建一个简单的命令行工具Xcode项目,尝试了与论坛内部类似的事情:

I tried something similar to what's inside the forum by creating a simple command-line tool Xcode project:

import Foundation
import os.log

os_log("rrrr")

并在终端中键入以下内容: log stream --source --predicate'eventMessage包含"rrrr"',我明白了:

and type the following in Terminal: log stream --source --predicate 'eventMessage contains "rrrr"', and I got this:

Timestamp                       Thread     Type        Activity             PID    
2017-02-18 17:58:46.012381+0700 0x5067d    Default     0x0                  5637   <testLogSwift`_swift_os_log> rrrr

与我在C/C ++版本中看到的相反,后者显示了文件和行号:

in contrast to what I got in C/C++ version, which shows the file and line number:

Timestamp                       Thread     Type        Activity             PID    
2017-02-18 17:55:05.056103+0700 0x4aa01    Default     0x0                  5218   <testLogging`main (main.cpp:13)> qqq

这篇关于如何从 os_log() 中查找源文件和行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆