首页 文章

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

提问于
浏览
617

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

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

11 回答

  • 1370

    试试这个:

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

    2-在您的环境变量集 OS_ACTIVITY_MODE = disable

  • 1

    好的 . 关于这个似乎有很多骚动,所以我会给你一个坚持它而不使用那个计划技巧的方法 . 我将特别针对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 . 现在,构建并运行您的应用程序并观察日志 . 您正在寻找紧随 subsystem: 部分的内容 . 紧随其后的名称代表相应的有问题的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" }}}

    祝好运 :]

  • 32

    请找到以下步骤 .

    • 选择产品=>方案=>编辑方案或使用快捷方式: CMD + <

    • 从左侧选择 Run 选项 .

    • 在“环境变量”部分,添加变量 OS_ACTIVITY_MODE = disable

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

  • 316

    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进行大修后,有一些问题就不足为奇了 .

    ADDENDUM

    无论如何, 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;
        }
    }
    
  • 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

  • 30

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

    • 在模拟器中运行应用程序

    • 打开系统日志( /

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

    要仅过滤NSLog语句:

    • 每个都带有符号前缀,例如: NSLog(@"^ Test Log")

    • 使用右上方的搜索框过滤结果,在上述情况下为"^"

    这是你应该得到的:

  • 63

    对于我来说,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调试控制台在模拟器中调试应用程序时显示来自系统框架的额外日志记录 . (27331147,26652255)

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

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

    • 前缀我的打印日志与某种特殊字符(例如*或^或!等等)

    • 然后使用控制台窗格右下角的搜索框通过输入我选择的特殊字符来过滤我的控制台日志让控制台按预期显示我的打印日志

  • 21

    我的解决方案是在断点中使用 debugger command 和/或 Log Message .

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

  • 13

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

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

    有效 .

  • 75

    在@rustyshelf的原始tweet的基础上,以及来自iDevzilla的图解答案,这是一个解决方案,可以消除来自模拟器的噪音而不会禁用设备的NSLog输出 .

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

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

  • 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)

相关问题