ios 隐藏奇怪的不需要的 Xcode 日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37800790/
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
Hide strange unwanted Xcode logs
提问by Hans Kn?chel
When using the Xcode 8+ and creating a new blank project, the following logs appear when running the application:
使用 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
Maybe someone already found a configuration for this to handle?
也许有人已经找到了一个配置来处理?
回答by iDevzilla
回答by cduhn
Building on the original tweetfrom @rustyshelf, and illustrated answer from iDevzilla, here's a solution that silences the noise from the simulator without disabling NSLog output from the device.
基于来自@rustyshelf的原始推文和来自 iDevzilla 的说明性答案,这里有一个解决方案,可以在不禁用设备的 NSLog 输出的情况下消除模拟器中的噪音。
- Under Product > Scheme > Edit Scheme... > Run (Debug), set the OS_ACTIVITY_MODE environment variable to ${DEBUG_ACTIVITY_MODE} so it looks like this:
- 在 Product > Scheme > Edit Scheme... > Run (Debug) 下,将 OS_ACTIVITY_MODE 环境变量设置为 ${DEBUG_ACTIVITY_MODE} 如下所示:
- Go to your project build settings, and click + to add a User-Defined Setting named DEBUG_ACTIVITY_MODE. Expand this setting and Click the + next to Debug to add a platform-specific value. Select the dropdown and change it to "Any iOS Simulator". Then set its value to "disable" so it looks like this:
- 转到您的项目构建设置,然后单击 + 添加名为 DEBUG_ACTIVITY_MODE 的用户定义设置。展开此设置并单击 Debug 旁边的 + 以添加特定于平台的值。选择下拉菜单并将其更改为“任何 iOS 模拟器”。然后将其值设置为“禁用”,如下所示:
回答by BaseZen
OS_ACTIVITY_MODE didn't work for me (it mayhave been because I typo'd disable
as disabled
, but isn't that more natural?!?), or at least didn't prevent a great deal of messages. So here's the real deal with the environment variables.
OS_ACTIVITY_MODE 对我不起作用(可能是因为我打错了disable
as disabled
,但这不是更自然吗?!?),或者至少没有阻止大量消息。所以这里是环境变量的真正处理。
https://llvm.org/svn/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
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);
}
So setting OS_ACTIVITY_DT_MODE
to "NO" in the environment variables (GUI method explained in Schemes screenshot in main answer) makes it work for me.
因此OS_ACTIVITY_DT_MODE
,在环境变量中设置为“NO”(主要答案中的 Schemes 屏幕截图中解释了 GUI 方法)使其对我有用。
As far as NSLog
being the dumping ground for system messages, errors, and your own debugging: a real logging approach is probably called for anyway, e.g. https://github.com/fpillet/NSLogger.
至于作为NSLog
系统消息、错误和您自己的调试的倾倒场:无论如何可能需要一种真正的日志记录方法,例如https://github.com/fpillet/NSLogger。
OR
或者
Drink the new Kool-Aid: http://asciiwwdc.com/2016/sessions/721https://developer.apple.com/videos/play/wwdc2016/721/It's not surprising that there are some hitches after overhauling the entire logging API.
喝新的Kool-Aid:http: //asciiwwdc.com/2016/sessions/721 https://developer.apple.com/videos/play/wwdc2016/721/整机大修后出现一些故障并不奇怪日志 API。
ADDENDUM
附录
Anyway, NSLog
is just a shim:
无论如何,NSLog
只是一个垫片:
https://developer.apple.com/library/content/releasenotes/Miscellaneous/RN-Foundation-OSX10.12/
https://developer.apple.com/library/content/releasenotes/Miscellaneous/RN-Foundation-OSX10.12/
NSLog / CFLog
NSLog is now just a shim to os_log in most circumstances.
NSLog / CFLog
在大多数情况下,NSLog 现在只是 os_log 的一个垫片。
Only makes sense now to quote the source for the other env variable. Quite a disparate place, this time from Apple internals. Not sure why they are overlapping. [Incorrect comment about NSLog
removed]
现在只引用另一个 env 变量的源代码才有意义。完全不同的地方,这次来自 Apple 内部。不知道为什么它们重叠。[关于NSLog
删除的错误评论]
[Edited 22 Sep]: I wonder what "release" and "stream" do differently than "debug". Not enough source.
[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;
}
}
回答by Peter Smith
A tweet had the answer for me - https://twitter.com/rustyshelf/status/775505191160328194
一条推文为我提供了答案 - https://twitter.com/rustyshelf/status/775505191160328194
To stop the Xcode 8 iOS Simulator from logging like crazy, set an environment variable OS_ACTIVITY_MODE = disable in your debug scheme.
要阻止 Xcode 8 iOS Simulator 疯狂地记录日志,请在您的调试方案中设置一个环境变量 OS_ACTIVITY_MODE = disable。
It worked.
有效。
回答by Ramkrishna Sharma
Please find the below steps.
请找到以下步骤。
- Select Product => Scheme => Edit Scheme or use shortcut :
CMD + <
- Select the
Run
option from left side. - On Environment Variables section, add the variable OS_ACTIVITY_MODE = disable
- 选择 Product => Scheme => Edit Scheme 或使用快捷方式:
CMD + <
Run
从左侧选择选项。- 在环境变量部分,添加变量OS_ACTIVITY_MODE = disable
For more information please find the below GIF representation.
有关更多信息,请参阅下面的 GIF 表示。
回答by Pez
This is still not fixed in Xcode Version 8.0 beta 2 (8S162m) for me and extra logs are also appearing in the Xcode console
这仍然没有在 Xcode Version 8.0 beta 2 (8S162m) 中修复,并且额外的日志也出现在 Xcode 控制台中
** EDIT 8/1/16: This has been acknowledged in the release notes for Xcode 8 Beta 4 (8S188o) as an issues still persisting.
** 编辑 8/1/16:这已在Xcode 8 Beta 4 (8S188o)的发行说明中确认为仍然存在的问题。
Known Issues in Xcode 8 beta 4 – IDE
Debugging
? Xcode Debug Console shows extra logging from system frameworks when debugging applications in the Simulator. (27331147, 26652255)
Xcode 8 beta 4 中的已知问题 – IDE
调试
? 在模拟器中调试应用程序时,Xcode 调试控制台会显示来自系统框架的额外日志记录。(27331147, 26652255)
Presumably this will be resolved by the GM release. Until then patience and although not ideal but a workaround I'm using is below...
据推测,这将通过 GM 版本解决。在那之前,耐心虽然不理想,但我正在使用的解决方法如下......
Similar to the previous answer I am having to:
与之前的答案类似,我必须:
prefix my print logs with some kind of special character (eg * or ^ or ! etc etc)
Then use the search box on the bottom right of the console pane to filter my console logs by inputing my chosen special character to get the console to display my print logs as intended
在我的打印日志前加上某种特殊字符(例如 * 或 ^ 或 ! 等)
然后使用控制台窗格右下角的搜索框通过输入我选择的特殊字符来过滤我的控制台日志,以使控制台按预期显示我的打印日志
回答by mrahmiao
回答by Sozin's Comet
Alright. There seems to be a lot of commotion about this one, so I'll give y'all a way to persist it without using that scheme trick. I'll address the iOS Simulator specifically, but this also might need to be applied for the TV Sim as well which is located in a different dir.
好吧。关于这个似乎有很多骚动,所以我会给你们一种方法来坚持它而不使用那个计划技巧。我将专门介绍 iOS 模拟器,但这也可能需要应用于位于不同目录中的 TV Sim。
The problem that is causing all of this stuff are plists located within the Xcode directory. There is a process that gets launched called configd_simwhen the Sim starts that reads the plists in and prints debugging information if the plists specify they should be logged.
导致所有这些东西的问题是位于 Xcode 目录中的 plist。当 Sim 启动时,有一个名为configd_sim的进程被启动,它读取 plists 并打印调试信息,如果 plists 指定它们应该被记录。
The plists are located here:
plist 位于此处:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Preferences/Logging/Subsystems
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Preferences/Logging/Subsystems
If you are playing around with a beta, take note that the dir will be different.
如果您正在玩测试版,请注意目录会有所不同。
You will see numerous plists in this directory. Now, build and run your application and observe the logs. You are looking for the content immediately followed by the subsystem:part. It is the name immediately following this that represents the corresponding problematic plist.
您将在此目录中看到许多 plist。现在,构建并运行您的应用程序并观察日志。您正在寻找紧跟在子系统后面的内容:部分。紧跟在此之后的名称代表相应的有问题的 plist。
From there, either modify the plist to knock out the debugging [Level] key/value which is a dictionary containing the "Enable" => "Default"
key/value... or just simply delete the plist. Note, that you will need to be root to do either of these since they're located in the Xcode application.
从那里,要么修改 plist 以淘汰调试 [Level] 键/值,它是一个包含"Enable" => "Default"
键/值的字典......或者只是简单地删除 plist。请注意,您需要是 root 用户才能执行其中任何一项操作,因为它们位于 Xcode 应用程序中。
the plutil -p
command might be of use to you as well. i.e.
该plutil -p
命令也可能对您有用。IE
plutil -p /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Preferences/Logging/Subsystems/com.apple.BackBoardServices.fence.plist
This gave me one of the problematic plists which contained:
这给了我一个有问题的 plist,其中包含:
{ "DEFAULT-OPTIONS" => { "Level" => { "Enable" => "Default" }}}
{ "DEFAULT-OPTIONS" => { "Level" => { "Enable" => "Default" }}}
Good luck :]
祝你好运 :]
回答by JAL
This is related to a known issue with logging found in the Xcode 8 Beta Release Notes(also asked an engineer at WWDC).
这与Xcode 8 Beta 发行说明中发现的已知日志问题有关(也询问了 WWDC 的工程师)。
When debugging WatchOS applications in the Watch simulator, the OS may produce an excessive amount of unhelpful logging. (26652255)
在 Watch 模拟器中调试 WatchOS 应用程序时,操作系统可能会产生过多无用的日志记录。(26652255)
There is currently no workaround available, you must wait for a new version of Xcode.
目前没有可用的解决方法,您必须等待 Xcode 的新版本。
EDIT 7/5/16: This is supposedly fixed as of Xcode 8 Beta 2:
编辑 7/5/16:这应该是从 Xcode 8 Beta 2 开始修复的:
Resolved in Xcode 8 beta 2 – IDE
Debugging
- When debugging an app on the Simulator, logs are visible. (26457535)
在 Xcode 8 beta 2 – IDE 中解决
调试
- 在模拟器上调试应用程序时,日志是可见的。(26457535)
回答by mriddle89
This is no longer an issue in xcode 8.1 (tested Version 8.1 beta (8T46g)). You can remove the OS_ACTIVITY_MODE
environment variable from your scheme.
这在 xcode 8.1 (tested Version 8.1 beta (8T46g)) 中不再是问题。您可以OS_ACTIVITY_MODE
从方案中删除环境变量。
https://developer.apple.com/go/?id=xcode-8.1-beta-rn
https://developer.apple.com/go/?id=xcode-8.1-beta-rn
Debugging
? Xcode Debug Console no longer shows extra logging from system frameworks when debugging applications in the Simulator. (26652255, 27331147)
调试
? 在模拟器中调试应用程序时,Xcode 调试控制台不再显示来自系统框架的额外日志记录。(26652255, 27331147)