使用Xcode 8+并创建新的空白项目时,运行应用程序时会显示以下日志:
2016-06-13 16:33:34.406093 TestiOS10[8209:100611] bundleid: com.appc.TestiOS10, enable_level: 0, persist_level: 0, propagate_with_activity: 0
2016-06-13 16:33:34.406323 TestiOS10[8209:100607] Created DB, header sequence number = 248
2016-06-13 16:33:34.409564 TestiOS10[8209:100611] subsystem: com.apple.UIKit, category: HIDEvents, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-06-13 16:33:34.504117 TestiOS10[8209:100607] Created DB, header sequence number = 248
2016-06-13 16:33:34.548023 TestiOS10[8209:100607] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-06-13 16:33:34.568458 TestiOS10[8209:100608] subsystem: com.apple.FrontBoard, category: Common, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
也许有人已经找到了这个配置来处理?
这在xcode 8.1(测试版本8.1 beta(8T46g))中不再是问题。您可以从方案中删除OS_ACTIVITY_MODE
环境变量。
https://developer.apple.com/go/?id=xcode-8.1-beta-rn
调试
•在模拟器中调试应用程序时,Xcode调试控制台不再显示来自系统框架的额外日志记录。 (26652255,27331147)
在Xcode 10中,OS_ACTIVITY_MODE
变量与disable
(或default
)值也会关闭NSLog
,无论如何。
因此,如果你想摆脱控制台噪音,而不是你自己的日志,你可以尝试使用旧的printf("")
而不是NSLog,因为它不受OS_ACTIVITY_MODE
= disable
的影响。
但最好查看新的os_log
API here。
在@rustyshelf的原始tweet的基础上,以及来自iDevzilla的图解答案,这是一个解决方案,可以在不禁用设备的NSLog输出的情况下使来自模拟器的噪声静音。
OS_ACTIVITY_MODE对我不起作用(可能是因为我把disable
称为disabled
,但不是更自然吗?!?),或者至少没有阻止大量的消息。所以这是对环境变量的真实处理。
https://llvm.org/svn/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb_private::Error
PlatformDarwin::LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) {
// Starting in Fall 2016 OSes, NSLog messages only get mirrored to stderr
// if the OS_ACTIVITY_DT_MODE environment variable is set. (It doesn't
// require any specific value; rather, it just needs to exist).
// We will set it here as long as the IDE_DISABLED_OS_ACTIVITY_DT_MODE flag
// is not set. Xcode makes use of IDE_DISABLED_OS_ACTIVITY_DT_MODE to tell
// LLDB *not* to muck with the OS_ACTIVITY_DT_MODE flag when they
// specifically want it unset.
const char *disable_env_var = "IDE_DISABLED_OS_ACTIVITY_DT_MODE";
auto &env_vars = launch_info.GetEnvironmentEntries();
if (!env_vars.ContainsEnvironmentVariable(disable_env_var)) {
// We want to make sure that OS_ACTIVITY_DT_MODE is set so that
// we get os_log and NSLog messages mirrored to the target process
// stderr.
if (!env_vars.ContainsEnvironmentVariable("OS_ACTIVITY_DT_MODE"))
env_vars.AppendArgument(llvm::StringRef("OS_ACTIVITY_DT_MODE=enable"));
}
// Let our parent class do the real launching.
return PlatformPOSIX::LaunchProcess(launch_info);
}
因此,在环境变量中将OS_ACTIVITY_DT_MODE
设置为“NO”(在主要答案的Schemes屏幕截图中解释的GUI方法)使其适用于我。
至于NSLog
是系统消息,错误和你自己的调试的倾销场:无论如何都可能需要一种真正的日志记录方法,例如: https://github.com/fpillet/NSLogger。
要么
喝新的Kool-Aid:http://asciiwwdc.com/2016/sessions/721 https://developer.apple.com/videos/play/wwdc2016/721/在对整个日志记录API进行大修后,有一些障碍就不足为奇了。
附录
无论如何,NSLog
只是一个垫片:
https://developer.apple.com/library/content/releasenotes/Miscellaneous/RN-Foundation-OSX10.12/
NSLog / CFLog
在大多数情况下,NSLog现在只是os_log的一个垫片。
现在只有引用其他env变量的源才有意义。相当不同的地方,这次来自Apple内部。不确定为什么它们重叠。 [删除NSLog
的错误评论]
[9月22日编辑]:我想知道“发布”和“流”与“调试”有什么不同。资源不足。
e = getenv("OS_ACTIVITY_MODE");
if (e) {
if (strcmp(e, "release") == 0) {
mode = voucher_activity_mode_release;
} else if (strcmp(e, "debug") == 0) {
mode = voucher_activity_mode_debug;
} else if (strcmp(e, "stream") == 0) {
mode = voucher_activity_mode_stream;
} else if (strcmp(e, "disable") == 0) {
mode = voucher_activity_mode_disable;
}
}
一条推文给了我答案 - https://twitter.com/rustyshelf/status/775505191160328194
要阻止Xcode 8 iOS模拟器疯狂记录,请在调试方案中设置环境变量OS_ACTIVITY_MODE = disable。
有效。
对于我来说,在Xcode版本8.0 beta 2(8S162m)中仍然没有修复此问题,Xcode控制台中也出现了额外的日志
**编辑8/1/16:这已在release notes for Xcode 8 Beta 4 (8S188o) as an issues still persisting中得到承认。
Xcode 8 beta 4中的已知问题 - IDE
调试
•在模拟器中调试应用程序时,Xcode Debug Console显示系统框架的额外日志记录。 (27331147,26652255)
据推测,这将由通用汽车发布解决。在那之前,耐心虽然不理想,但我正在使用的解决方法是......
与之前的答案类似,我不得不:
这与Xcode 8 Beta Release Notes中发现的已知问题有关(也问过WWDC的工程师)。
在Watch模拟器中调试WatchOS应用程序时,操作系统可能会产生过多的无用日志记录。 (26652255)
目前没有可用的解决方法,您必须等待新版本的Xcode。
编辑7/5/16:从Xcode 8 Beta 2开始,这应该是固定的:
已在Xcode 8 beta 2 - IDE中得到解决
调试
- 在模拟器上调试应用程序时,日志可见。 (26457535)
好的。关于这个似乎有很多骚动,所以我会给你一个方法来坚持它而不使用那个计划技巧。我将专门针对iOS模拟器,但这也可能需要应用于电视模拟器,它位于不同的目录。
引起所有这些问题的问题是位于Xcode目录中的plists。当Sim开始读取plist并打印调试信息时,如果plist指定应记录它们,则会启动一个名为configd_sim的进程。
柱子位于这里:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Preferences/Logging/Subsystems
如果你正在玩beta版,请注意dir会有所不同。
您将在此目录中看到许多plists。现在,构建并运行您的应用程序并观察日志。您正在寻找子系统紧随其后的内容:部分。紧随其后的名称代表相应的有问题的plist。
从那里,修改plist以淘汰调试[Level]键/值,这是一个包含"Enable" => "Default"
键/值的字典......或者只是简单地删除plist。请注意,由于它们位于Xcode应用程序中,因此您需要是root用户才能执行其中任何一项操作。
plutil -p
命令也可能对你有用。即
plutil -p /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Preferences/Logging/Subsystems/com.apple.BackBoardServices.fence.plist
这给了我一个有问题的plists包含:
{ "DEFAULT-OPTIONS" => { "Level" => { "Enable" => "Default" }}}
祝好运 :]