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

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

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


尝试这个:

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

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

截图


基于来自@rustyshelf的原始推文,以及来自iDevzilla的解答,这里提供了一种解决方案,可以在不禁用NSLog输出的情况下使模拟器的噪声静音。

  • 在产品>方案>编辑方案...>运行(调试)下,将OS_ACTIVITY_MODE环境变量设置为$ {DEBUG_ACTIVITY_MODE},如下所示:
  • 在这里输入图像描述

  • 转到您的项目构建设置,然后单击+添加名为DEBUG_ACTIVITY_MODE的用户定义设置。 展开此设置并单击“调试”旁边的+以添加特定于平台的值。 选择下拉列表并将其更改为“Any iOS Simulator”。 然后将其值设置为“禁用”,如下所示:
  • 在这里输入图像描述


    OS_ACTIVITY_MODE对我来说不起作用(可能是因为我disabledisabled字符串,但并不那么自然?!?),或者至少没有阻止大量的消息。 所以这里是对环境变量的真正处理。

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

    因此,在环境变量(主要答案中的方案截图中介绍的GUI方法) OS_ACTIVITY_DT_MODE设置为“NO”使其适用于我。

    至于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变量的来源才有意义。 这是来自苹果内部的完全不同的地方。 不知道他们为什么重叠。 [删除关于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;
        }
    }
    
    链接地址: http://www.djcxy.com/p/68685.html

    上一篇: Hide strange unwanted Xcode logs

    下一篇: Xcode 6 strange (null) object display in debugger