Hide strange unwanted Xcode logs

When using the Xcode 8+ and creating a new blank project, the following logs appear when running the application:

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?


Try this:

1- From Xcode menu open: Product > Scheme > Edit Scheme

2- On your Environment Variables set OS_ACTIVITY_MODE = disable

截图


Building on the original tweet from @rustyshelf, and illustrated answer from iDevzilla, here's a solution that silences the noise from the simulator without disabling NSLog output from the device.

  • Under Product > Scheme > Edit Scheme... > Run (Debug), set the OS_ACTIVITY_MODE environment variable to ${DEBUG_ACTIVITY_MODE} so it looks like this:
  • 在这里输入图像描述

  • 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:
  • 在这里输入图像描述


    OS_ACTIVITY_MODE didn't work for me (it may have 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.

    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.

    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, eg https://github.com/fpillet/NSLogger .

    OR

    Drink the new Kool-Aid: http://asciiwwdc.com/2016/sessions/721 https://developer.apple.com/videos/play/wwdc2016/721/ It's not surprising that there are some hitches after overhauling the entire logging API.

    ADDENDUM

    Anyway, NSLog is just a shim:

    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.

    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]

    [Edited 22 Sep]: I wonder what "release" and "stream" do differently than "debug". Not enough source.

    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/68686.html

    上一篇: Xcode调试器不适用于具有多个目标的项目

    下一篇: 隐藏奇怪的不需要的Xcode日志