How do I display this Log message in the Debug area using Xcode9?

This looked promising but doesn’t seem like a duplicate question as it addresses issues in Swift.

I am finalising an existing Objective C project but NSLog disappeared when I updated to Xcode 9. So I’m looking for some setting in Xcode that lets me continue using NSLog to fine tune the project.

  • Xcode 9 Server: Unable to boot device due to insufficient system resources
  • Xcode 9 iOS Simulator - Unable To Obtain Valid Process Handle
  • How to create Named colors in Interface Builder?
  • Xcode 9 / iOS 11 “CALayer bounds contains NaN: ” when popping view controller with nested UINavigationController and UITabBarController
  • Main Thread Checker: UI API called on a background thread iOS 11 Xcode 9 GM Seed
  • NSUnknownKeyException : was sent to an object that is not KVC-compliant for the “player” property
  • Basic debugging using logging for Swift and Objective-C apps appears to have changed in Xcode 9 as NSLog messages no longer appear in the Debug area. The window where DEBUG=1 is set no longer looks like Figure 2 The DEBUG preprocessor macro setting in an Xcode project.

    As an example, I want to display this string message in the Debug area using Xcode9.

        NSString *outputData = @"This should show in Debug area";
        NSLog( @"text: %@", outputData );

    I studied the latest documentation here or here but so far that has not helped. It may also be worth noting that previously the Debug area would open automatically when I ran the project. Since installing Xcode9 it no longer does that.

    Hopefully the extra information provided in the edits below will suggest to someone where I have yet to look. Thanks.

    EDIT 1

    In the Console area – i.e. the bottom right part of the Debug area – I had All Output selected. So I tried using Debugger output and Target output but there was still no log.

    I added these statements in the Prefix.pch file

    #ifndef DEBUG
    #define NSLog(...) /* suppress NSLog when in release mode 

    When I ran the code the following appeared in the Issue Navigator.

        Unused variable 'outputData'

    EDIT 2

    There seems to be a different place to set DEBUG=1 in Xcode9 (see below).

    I inserted a DEBUG macro into the .pch file using the examples suggested in several SO posts here, here, here (all quite old) and even here (making sure to change MyLog back to NSLog). And in each case I was able to report the same issue in the Issue navigator but never in the Debug console. A similar problem (with Xcode5) was solved here by copying over the files into a new project but I want to avoid this.

    My app which was almost finished has so far not had to deal with any of the complex issues that unified logging seeks to address. But I watched the 2016 WWDC video on unified logging and read through its slide show files searching for an example of how to use the appropriate API to do something as basic – print NSLog live to the console area – the way I did before installing Xcode9. This may be the wrong approach. But I can’t think of a better way to proceed.

    EDIT 3

    It’s worth noting that when I created a new Objective C project using Xcode9 and ran the above code, the string message appeared in the Console area.

    In other words, using Xcode9 the new logging API does work with NSLog, but only for a new project and not for one created using an earlier version of Xcode.

    Enable DEBUG preprocessor macro

    The DEBUG preprocessor macro setting in an Xcode project.

    3 Solutions Collect From Internet About “How do I display this Log message in the Debug area using Xcode9?”

    Rather than writing your debug statement into code, you might try dropping in a breakpoint, right clicking on it, and selecting “Edit Breakpoint”. You should see this menu:

    enter image description here

    From there, you’ll click “Edit Breakpoint” and you’re presented with this:

    enter image description here

    From there, you can click “Action” and you’ll see this menu:

    enter image description here

    You can enter print messages (ex: myMethodCalled) or variable values (myIntValue = @myIntValue@), or you can type debugger commands to execute at that spot in the code (ex: po dump(myArray)).

    The downside of this approach is the breakpoints aren’t always “sticky” to the line of code you originally drop it in on.

    Try this. Navigate to:

    Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables

    in Xcode.

    Add OS_ACTIVITY_MODE and set the value to disable or leave it empty.

    Make sure it is checked!

    Hope this helps

    A Debug log was enabled in the Console area of Xcode9 after replacing these definitions in the preCompile header

        #ifndef DEBUG
        #define NSLog(...) /* suppress NSLog when in release mode */ 

    with the following

        #ifdef __DEBUG__
        #define NSLog(...) /* suppress NSLog when in release mode */

    Environment Variables for Arguments were set according to the answer above with an additional setting for Options. Someone more familiar with the unified logging API might explain the particular options but I’m satisfied I have a working solution.


    enter image description here


    enter image description here