xcode 在设备控制台中查看 os_log 消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46660112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Viewing os_log messages in device console
提问by Nitay
I'm trying to get some logging out of my app through Unified Logging (os_log)
我正在尝试通过统一日志记录 (os_log) 退出我的应用程序
Here's the initialization of the log:
下面是日志的初始化:
var osLog : OSLog = OSLog(subsystem: "com.test.testapp", category: "native-tester")
And here's how I use it:
这是我如何使用它:
os_log("iOS App initialized successfully!", log: osLog, type:.info)
When debugging the app normally, the logs appear properly on the console output, but when I look at the device console (Shown in the "Devices and Simulators" window) I don't see them at all.
正常调试应用程序时,日志正确显示在控制台输出中,但是当我查看设备控制台(显示在“设备和模拟器”窗口中)时,我根本看不到它们。
This articlesays that you should configure the system to enable the debug logs using
这篇文章说你应该配置系统以启用调试日志使用
sudo log config --mode "level:debug" --subsystem com.test.testapp
But that didn't seem to make a difference. I'm guessing it's because I'm configuring the mac to view the logs, not the iPad.
但这似乎并没有什么不同。我猜这是因为我正在配置 mac 来查看日志,而不是 iPad。
How do I view the ipad / iphone logs from os_log in the device console?
如何从设备控制台中的 os_log 查看 ipad / iphone 日志?
回答by leanne
The "Devices and Simulators" window only shows crash reports. Use the Console app or Terminal, via the log --stream
command, to see live log output.
“设备和模拟器”窗口仅显示崩溃报告。通过log --stream
命令使用控制台应用程序或终端查看实时日志输出。
To see the device's live log messages via the Console app, either when running from Xcode or when running from the device directly:
要通过控制台应用程序查看设备的实时日志消息,无论是从 Xcode 运行时还是直接从设备运行时:
- Open Console.app.
- Click on the device's name in the left side panel, under "Devices".
- Select Action, then Include Info Messagesfrom the menu. If you are also using
.debug
level messages, make sure to select Include Debug Messagesas well. (Without those items selected, the Console displays.default
,.fault
, and.error
level messages only.)
- 打开 Console.app。
- 单击左侧面板中“设备”下的设备名称。
- 选择Action,然后从菜单中选择Include Info Messages。如果您还使用
.debug
级别消息,请确保也选择包括调试消息。(如果没有选择的那些项目,该控制台显示.default
,.fault
和.error
级别的消息只)。
If you still don't see the messages, try entering this Terminal command to configure the logging levels for your app:
如果您仍然没有看到消息,请尝试输入此终端命令来为您的应用程序配置日志记录级别:
sudo log config --subsystem com.test.testapp --mode level:debug
This turns on .debug
-level logging for subsystem "com.test.testapp" (which includes .info
and .default
messages).
这导通.debug
-电平日志记录子系统“com.test.testapp”(其包括.info
与.default
消息)。
If you want to persist the messages, rather than the default of memory-only, turn on persistence for the three levels at the same time, like so:
如果你想持久化消息,而不是默认的仅内存,同时打开三个级别的持久化,如下所示:
sudo log config --subsystem com.test.testapp --mode level:debug,persist:debug
Regardless of any log settings, though, only crash reports will appear in the "Devices and Simulators" window.
但是,无论任何日志设置如何,“设备和模拟器”窗口中都只会显示崩溃报告。
回答by samwize
Another pitfall: If you have set OS_ACTIVITY_MODE
to disable
in your scheme, then you will not see any logs for your app in console.
另一个陷阱:如果您在您的方案中设置OS_ACTIVITY_MODE
了disable
,那么您将不会在控制台中看到您的应用程序的任何日志。
You have to remove or uncheck that argument.
您必须删除或取消选中该参数。
回答by Tomasz Czy?ak
Logs type .debug and .info are by default memory only (not saved on disk) so it won't be visible on device console.
日志类型 .debug 和 .info 默认情况下仅为内存(不保存在磁盘上),因此在设备控制台上不可见。
Detailed info: https://developer.apple.com/documentation/os/logging?language=objc
详细信息:https: //developer.apple.com/documentation/os/logging?language=objc
Also here is pretty nice WWDC: https://developer.apple.com/videos/play/wwdc2016/721/
这里还有非常好的 WWDC:https: //developer.apple.com/videos/play/wwdc2016/721/
回答by Ross
My os_log went missing after releasing an app to app store. I guess when I built the app for release, the debug option was turned off.
将应用程序发布到应用程序商店后,我的 os_log 丢失了。我猜当我构建要发布的应用程序时,调试选项被关闭了。
To enable the logging back... go to Product > Scheme > Edit Scheme > Run Debug ... then check Debug executable.
要启用回登录...转到产品>方案>编辑方案>运行调试...然后检查调试可执行文件。