使用 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
也许有人已经找到了要处理的配置?
该解决方案以 @rustyshelf 的原始推文为基础,并通过 iDevzilla 给出了图解说明,此解决方案可在不禁用设备的 NSLog 输出的情况下使模拟器的噪声静音。
OS_ACTIVITY_MODE 没有工作对我来说(这可能是因为我 typo'd 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”(主要答案的 “方案” 屏幕截图中说明的 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;
}
}