隐藏奇怪的不需要的Xcode日志

问题描述 投票:646回答:12

使用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

也许有人已经找到了这个配置来处理?

ios xcode logging xcode8 ios10
12个回答
1422
投票

试试这个:

1-从Xcode菜单打开:产品>方案>编辑方案

2-在您的环境变量上设置OS_ACTIVITY_MODE = disable

Screenshot


7
投票

这在xcode 8.1(测试版本8.1 beta(8T46g))中不再是问题。您可以从方案中删除OS_ACTIVITY_MODE环境变量。

https://developer.apple.com/go/?id=xcode-8.1-beta-rn

调试

•在模拟器中调试应用程序时,Xcode调试控制台不再显示来自系统框架的额外日志记录。 (26652255,27331147)


1
投票

这个解决方案一直在为我工作:

  1. 在模拟器中运行应用程序
  2. 打开系统日志( + /

这将转储所有调试数据以及NSLog。

要仅过滤NSLog语句:

  1. 每个都带有符号前缀,例如:NSLog(@"^ Test Log")
  2. 使用右上角的搜索框过滤结果,上面的情况为“^”

这是你应该得到的:

Screenshot of console


0
投票

在Xcode 10中,OS_ACTIVITY_MODE变量与disable(或default)值也会关闭NSLog,无论如何。

因此,如果你想摆脱控制台噪音,而不是你自己的日志,你可以尝试使用旧的printf("")而不是NSLog,因为它不受OS_ACTIVITY_MODE = disable的影响。

但最好查看新的os_log API here


339
投票

在@rustyshelf的原始tweet的基础上,以及来自iDevzilla的图解答案,这是一个解决方案,可以在不禁用设备的NSLog输出的情况下使来自模拟器的噪声静音。

  1. 在Product> Scheme> Edit Scheme ...> Run(Debug)下,将OS_ACTIVITY_MODE环境变量设置为$ {DEBUG_ACTIVITY_MODE},如下所示:

enter image description here

  1. 转到项目构建设置,然后单击+以添加名为DEBUG_ACTIVITY_MODE的用户定义设置。展开此设置并单击Debug旁边的+以添加特定于平台的值。选择下拉列表并将其更改为“Any iOS Simulator”。然后将其值设置为“禁用”,所以它看起来像这样:

enter image description here


78
投票

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日编辑]:我想知道“发布”和“流”与“调试”有什么不同。资源不足。

https://github.com/macosforge/libdispatch/blob/8e63547ea4e5abbfe55c0c3064181c4950a791d3/src/voucher.c

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;
    }
}

63
投票

一条推文给了我答案 - https://twitter.com/rustyshelf/status/775505191160328194

要阻止Xcode 8 iOS模拟器疯狂记录,请在调试方案中设置环境变量OS_ACTIVITY_MODE = disable。

有效。


32
投票

对于我来说,在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)

据推测,这将由通用汽车发布解决。在那之前,耐心虽然不理想,但我正在使用的解决方法是......

与之前的答案类似,我不得不:

  • 使用某种特殊字符(例如*或^或!等等)为我的打印日志添加前缀
  • 然后使用控制台窗格右下角的搜索框通过输入我选择的特殊字符来过滤我的控制台日志,以使控制台按预期显示我的打印日志

console


32
投票

请找到以下步骤。

  1. 选择Product => Scheme => Edit Scheme或使用快捷方式:CMD + <
  2. 从左侧选择Run选项。
  3. 在“环境变量”部分,添加变量OS_ACTIVITY_MODE = disable

有关更多信息,请参阅以下GIF表示。

Edit Scheme


21
投票

我的解决方案是在断点中使用调试器命令和/或日志消息。

enter image description here

并将控制台的输出从All Output更改为Debugger Output

enter image description here


13
投票

这与Xcode 8 Beta Release Notes中发现的已知问题有关(也问过WWDC的工程师)。

在Watch模拟器中调试WatchOS应用程序时,操作系统可能会产生过多的无用日志记录。 (26652255)

目前没有可用的解决方法,您必须等待新版本的Xcode。

编辑7/5/16:从Xcode 8 Beta 2开始,这应该是固定的:

已在Xcode 8 beta 2 - IDE中得到解决

调试

  • 在模拟器上调试应用程序时,日志可见。 (26457535)

Xcode 8 Beta 2 Release Notes


13
投票

好的。关于这个似乎有很多骚动,所以我会给你一个方法来坚持它而不使用那个计划技巧。我将专门针对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。

enter image description here

从那里,修改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" }}}

祝好运 :]

© www.soinside.com 2019 - 2024. All rights reserved.