Hide strange unwanted Xcode logs

前端 未结 13 2751
孤独总比滥情好
孤独总比滥情好 2020-11-22 02:34

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:1         


        
相关标签:
13条回答
  • 2020-11-22 03:21

    My solution is to use the debugger command and/or Log Message in breakpoints.

    And change the output of console from All Output to Debugger Output like

    0 讨论(0)
  • 2020-11-22 03:23

    Please find the below steps.

    1. Select Product => Scheme => Edit Scheme or use shortcut : CMD + <
    2. Select the Run option from left side.
    3. On Environment Variables section, add the variable OS_ACTIVITY_MODE = disable

    For more information please find the below GIF representation.

    0 讨论(0)
  • 2020-11-22 03:24

    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, e.g. 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;
        }
    }
    
    0 讨论(0)
  • 2020-11-22 03:25

    Try this:

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

    2- On your Environment Variables set OS_ACTIVITY_MODE = disable

    0 讨论(0)
  • 2020-11-22 03:26

    Please note that for iOS 14 Simulator, the OS_ACTIVITY_MODE=disable will not show any logs using the new Swift Logger. You will have to remove or enable it.

    0 讨论(0)
  • 2020-11-22 03:31

    A tweet had the answer for me - 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.

    It worked.

    0 讨论(0)
提交回复
热议问题