Apple统一日志记录-如何获取文件名和行号 [英] Apple unified logging - how to get file name and line number

查看:119
本文介绍了Apple统一日志记录-如何获取文件名和行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple的 Unified Logging文档指出:

Apple's Unified Logging documentation states:

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

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

但是在控制台中,我看不到文件名,类名,函数名或行号.

But in Console I don't see a filename, class name, function name, or line numbers.

如何在我的日志中记录这些内容?

How can I have those in my logs?

推荐答案

os_log当前未在Console.app中或通过log stream命令提供Swift代码的行号/功能名称.

os_log doesn't currently give line numbers/function names for Swift code in Console.app, or through the log stream command.

如果您确实需要它-您可以使用文字表达像这样通过NSLogos_log手动传递信息:

If you really need it - you can use Literal Expressions to pass the information manually via NSLog or os_log like this:

os_log(.info, "Log message from file: %s, line: %i, column: %i", #file, #line, #column)

包装os_log以始终包含此信息可能很诱人,但是Apple建议出于性能原因不这样做.

It may be tempting to wrap os_log to always include this information, but Apple suggests not doing so for performance reasons.

这篇关于Apple统一日志记录-如何获取文件名和行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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