问题
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.
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).
Anyone figured it out yet?
回答1:
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.
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")
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
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
来源:https://stackoverflow.com/questions/40757530/how-to-find-source-file-and-line-number-from-os-log