Apple unified logging - how to get file name and l

2019-06-25 08:34发布

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?

1条回答
Ridiculous、
2楼-- · 2019-06-25 08:57

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

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)

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

查看更多
登录 后发表回答