iOS 10 不打印 NSLogs

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37886600/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:26:29  来源:igfitidea点击:

iOS 10 doesn't print NSLogs

iosxcodenslogxcode8ios10

提问by Tyler Sheaffer

Nothing prints from NSLogon Xcode 8.0 beta (8S128d). printfis unchanged

NSLog在 Xcode 8.0 beta (8S128d) 上没有打印任何内容。printf不变

Here's my code:

这是我的代码:

NSLog(@"hello from NSLog");
printf("hello from printf");

Here's the output on iOS 9 Simulator:

这是 iOS 9 模拟器上的输出:

2016-06-17 09:49:10.887 calmapp-dev[28517:567025] hello from NSLog
hello from printf

Here's the output on iOS 10 Simulator:

这是 iOS 10 模拟器上的输出:

hello from printf

回答by user6833743

It could be that you added the property "OS_ACTIVITY_MODE": "disable" in the Scheme environment variables (to hide OS output from the simulator) and forgot about it, and now are running on a real device.

可能是您在 Scheme 环境变量中添加了属性 "OS_ACTIVITY_MODE": "disable"(以隐藏模拟器的操作系统输出)并忘记了它,现在正在真实设备上运行。

In Xcode 8:

在 Xcode 8 中:

Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables

Only add OS_ACTIVITY_MODEand check it(Don't add a value)

只添加OS_ACTIVITY_MODE和检查它(不要添加值)

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Summary: This is a bug of Xcode 8 + iOS10, we can solve it in this way:

总结:这是Xcode 8 + iOS10的一个bug,我们可以这样解决:

  • When using the simulator, add the Name "OS_ACTIVITY_MODE" and the Value "disable" and check it.

  • When on a real device, only add "OS_ACTIVITY_MODE" and check it(Don't add the Value). You will see the NSLog in the Xcode8 Console.

  • 使用模拟器时,添加名称“OS_ACTIVITY_MODE”和值“禁用”并检查它。

  • 在真机上时,只添加“OS_ACTIVITY_MODE”并勾选(不要添加值)。您将在 Xcode8 控制台中看到 NSLog。

回答by Lucas

If you check the Xcode 8 beta release notes, you'll find that it says:

如果您查看Xcode 8 beta 发行说明,您会发现它说:

When debugging an app running on Simulator, logs may not be visible in the console. Workaround: Use command + / in Simulator.app to open the system log in the Console app to view NSLogs. (26457535)

调试在模拟器上运行的应用程序时,控制台中可能看不到日志。解决方法:在 Simulator.app 中使用 command + / 打开 Console app 中的系统日志,查看 NSLogs。(26457535)

回答by MiladiuM

the NSlog or print actually is executed but is hidden among lots of other console debug outputs to solve this issue Open Xcode8:

NSlog 或 print 实际上已执行,但隐藏在许多其他控制台调试输出中以解决此问题打开 Xcode8:

Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables

add "OS_ACTIVITY_MODE" and set the Value to "disable" and check it.

添加“OS_ACTIVITY_MODE”并将值设置为“禁用”并检查它。

click close

点击关闭

xcode9

xcode9

add "OS_ACTIVITY_MODE" and set the Value to "default" and check it.

添加“OS_ACTIVITY_MODE”并将值设置为“default”并检查它。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by kientux

I can't see NSLog output in real iOS 10 device neither. If you're using real devices, you can open Devices window from Xcode (Shift + Command + 2) and see device logs there, but it's hard to look at your app's logs because the console shows logs from system and all apps.

我也看不到真正的 iOS 10 设备中的 NSLog 输出。如果您使用的是真实设备,您可以从 Xcode (Shift + Command + 2) 打开 Devices 窗口并在那里查看设备日志,但很难查看您的应用程序日志,因为控制台会显示来自系统和所有应用程序的日志。

(I'm using Xcode 7, so it's may not Xcode's problem but iOS 10 problem)

(我使用的是 Xcode 7,所以这可能不是 Xcode 的问题,而是 iOS 10 的问题)

回答by Stewart Macdonald

Also, make sure the Console is actually visible in Xcode (i.e., make sure the right-hand side icon is highlighted in blue, as per the image below). After I upgraded Xcode, it hide the Console and showed me just the Variables view. This made it look like NSLog()was not working properly, whereas it was indeed working correct, I just couldn't see the output.

此外,确保控制台在 Xcode 中实际可见(即,确保右侧图标以蓝色突出显示,如下图所示)。升级 Xcode 后,它隐藏了控制台,只显示了变量视图。这使它看起来NSLog()工作不正常,但它确实工作正常,我只是看不到输出。

enter image description here

在此处输入图片说明

回答by David Hersey

Hmmm... it seems like the property "OS_ACTIVITY_MODE": "disable" PREVENTS NSlog from showing up in the Xcode 9 log.

嗯...似乎属性 "OS_ACTIVITY_MODE": "disable" PREVENTS NSlog 不会出现在 Xcode 9 日志中。

Unchecking this value in my scheme restored my logs.

在我的方案中取消选中这个值恢复了我的日志。

回答by shane

For anyone who comes upon this in the future. The reason NSLog doesn't print to syslog in iOS 10 and iOS 11 is due to Apple changing to Unified Logging.

对于将来遇到此问题的任何人。NSLog 在 iOS 10 和 iOS 11 中没有打印到 syslog 的原因是由于 Apple 更改为统一日志记录。

You can see the WWDC talk about it here: https://developer.apple.com/videos/play/wwdc2016/721/

你可以在这里看到 WWDC 谈论它:https: //developer.apple.com/videos/play/wwdc2016/721/

Documentation here: https://developer.apple.com/documentation/os/logging

此处的文档:https: //developer.apple.com/documentation/os/logging

From 10 on you should be using os_log instead of NSLog.

从 10 开始,您应该使用 os_log 而不是 NSLog。

How to find the logs on disk: https://www.blackbagtech.com/blog/2017/09/22/accessing-unified-logs-image/

如何在磁盘上查找日志:https: //www.blackbagtech.com/blog/2017/09/22/accessing-unified-logs-image/

To summarize, the logs are located in /var/db/diagnosticswhich can be found for a VM at /Users/USERNAME/Library/Developer/CoreSimulator/Devices/SIMULATOR-GUID/data/var/db/

总而言之,日志所在的位置/var/db/diagnostics可以在以下位置找到 VM/Users/USERNAME/Library/Developer/CoreSimulator/Devices/SIMULATOR-GUID/data/var/db/

Copy all items inside diagnosticsand uuidtextinto a single folder (don't include the folders diagnostics or uuidtext just what is inside).

副本中的所有项目diagnostics,并uuidtext到一个文件夹(不包括文件夹诊断或uuidtext只是里面是什么)。

Rename that folder foldername.xarchive.

重命名该文件夹foldername.xarchive

Open it in Console.app or use the OSX util log: log show <path to archive> --info --predicate <options>

在 Console.app 中打开它或使用 OSX util loglog show <path to archive> --info --predicate <options>

回答by Greg

NSLogmessages no longer displayed when I upgraded to Xcode 9.1 + iOS 11.1. Initially the accepted answergave me a way to work around this using the Console app and enabling the Simulator (see Lucas' answer).

NSLog当我升级到 Xcode 9.1 + iOS 11.1 时不再显示消息。最初,接受的答案为我提供了一种使用控制台应用程序并启用模拟器来解决此问题的方法(请参阅 Lucas 的答案)。

In the Console app under ActionI tried selecting Include Debug Messagesand deselecting Include Info Messages(so the Console isn't swamped with system messages). NSLogmessages appeared in the Console window in Xcode but not in the Console app.

在控制台应用程序下,Action我尝试选择Include Debug Messages和取消选择Include Info Messages(因此控制台不会被系统消息淹没)。NSLog消息出现在 Xcode 的控制台窗口中,但没有出现在控制台应用程序中。

I realised there had to be a more direct way to disableor enable (i.e. default) NSLogsthanks to Coeur's comment in response to this answer.In my opinion it is the best answer because setting OS_ACTIVITY_MODEto disableor defaultwill make more sense for beginners.

由于 Coeur 对这个答案的评论,我意识到必须有一种更直接的方式来disable或启用(即default在我看来,这是最好的答案,因为设置为或对初学者更有意义。NSLogsOS_ACTIVITY_MODEdisabledefault

回答by user6733740

I'm using Xcode 8,so I also encountered the same problem . And I solved this problem by adding value = disableon the simulator, but on a real machine I don't add value.

我使用的是 Xcode 8,所以我也遇到了同样的问题。我通过value = disable在模拟器上添加解决了这个问题,但是在真机上我没有增加价值。