91

Nothing prints from NSLog on Xcode 8.0 beta (8S128d). printf is unchanged

Here's my code:

NSLog(@"hello from NSLog");
printf("hello from printf");

Here's the output on iOS 9 Simulator:

2016-06-17 09:49:10.887 calmapp-dev[28517:567025] hello from NSLog
hello from printf

Here's the output on iOS 10 Simulator:

hello from printf
Tyler Sheaffer
  • 1,953
  • 1
  • 16
  • 16
  • I had a similar issue. But in iOS 8.1, Xcode 8. I checked each and every answer here. Turns out that I was doing everything correctly. Nothing really helped. So, I switched off the device and switched it on. It works. I wrote this comment here so that it may help others facing a similar problem – KrishnaCA Mar 06 '17 at 06:56

9 Answers9

232

It could be that you added the property "OS_ACTIVITY_MODE": "disable" in the Scheme environment variables (to hide OS output from the simulator) and forgot about it, and now are running on a real device.

In Xcode 8:

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

Only add OS_ACTIVITY_MODE and check it(Don't add a value)

enter image description here

enter image description here

Summary: This is a bug of Xcode 8 + iOS10, we can solve it in this way:

  • When using the simulator, add the Name "OS_ACTIVITY_MODE" and the Value "disable" and check it.

  • When on a real device, only add "OS_ACTIVITY_MODE" and check it(Don't add the Value). You will see the NSLog in the Xcode8 Console.

Wouter
  • 1,568
  • 7
  • 28
  • 35
user6833743
  • 2,329
  • 1
  • 8
  • 4
  • 4
    >"Don't add the Value" I set it to "disable" and it works! Empty field doesn't work for me. – m8labs Sep 16 '16 at 16:35
  • Are you sure it works when real iphone device debugging, not the simulator ? If I set it to "disable", the console can't NSLog when real iphone debugging. – user6833743 Sep 18 '16 at 10:05
  • I've checked now without "disable", it works on device now, but broken on simulator, it shows everything now again... – m8labs Sep 18 '16 at 10:16
  • Yep, that's it ! The way to solve the bug of Xcode8 + iOS10: When on sumulator, add the Name "OS_ACTIVITY_MODE" and the Value "disable" and check it. When on device, only add "OS_ACTIVITY_MODE" and check it(Don't add the Value). You will see the NSLog in the Xcode8 Console. – user6833743 Sep 19 '16 at 03:10
  • I have only add "OS_ACTIVITY_MODE" and check it(Don't add the Value). It will not print whole NSLog statement in the Xcode8 Console. If I print NSArray of 100 records then it will display some records and then break. – ChandreshKanetiya Oct 12 '16 at 13:33
  • Is there a way to use specify different environment variables based on architecture so that I can enable OS_ACTIVITY_MODE only on simulator? – Toland Hon Oct 14 '16 at 17:21
  • 2
    is there anyway to automate this process? its really really annoying that we have to remember to go back and forth like this : / – greenhouse Nov 01 '16 at 23:02
  • I have a SDK project, I put my own log there, it is not working on my iOS10 device, but still working on my iOS9 device. I follow the same way to change SDK and my SDK test app with this "disable", still now working on my side. Any idea? thanks. – xiaoyaoworm Jan 06 '17 at 22:45
  • just a comment that if one is too lazy to enable OS_ACTIVITY_MODE then dump will output variables regardless of OS_ACTIVITY_MODE value. – Max MacLeod Jun 20 '17 at 09:54
  • Thanks, made my day! – fruitcoder Sep 07 '17 at 10:58
  • Setting `OS_ACTIVITY_MODE` to `DEBUG_MODE` makes sure logs are seen only in debug mode. – LazyLastBencher Sep 20 '17 at 21:48
  • 2
    This solution will hide all NSLog starting with Xcode 9. To keep NSLog, replace `disable` with `default`. – Cœur Sep 27 '17 at 19:20
27

If you check the Xcode 8 beta release notes, you'll find that it says:

When debugging an app running on Simulator, logs may not be visible in the console. Workaround: Use command + / in Simulator.app to open the system log in the Console app to view NSLogs. (26457535)

Lucas
  • 880
  • 7
  • 12
  • 9
    I can't see NSLog output in real iOS 10 device neither. If you're using real devices, you can open Devices window (Shift + Command + 2) and see device logs there, but it's hard to look at debugging app log because the console shows all logs from system and apps. – kientux Jun 23 '16 at 01:16
19

the NSlog or print actually is executed but is hidden among lots of other console debug outputs to solve this issue Open Xcode8:

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

add "OS_ACTIVITY_MODE" and set the Value to "disable" and check it.

click close

xcode9

add "OS_ACTIVITY_MODE" and set the Value to "default" and check it.

enter image description here enter image description here

MiladiuM
  • 1,449
  • 16
  • 17
  • This does not work for me. NSLogs do not show up for deployed applications. I use xcode 8.1(running on Mac 10.11) with iOS 10 device. – mobjug Dec 15 '16 at 06:26
  • 22
    This solution will hide all NSLog starting with Xcode 9. To keep NSLog, replace `disable` with `default`. – Cœur Sep 27 '17 at 19:21
  • 3
    This answer should be updated to account for @Cœur's correction for Xcode 9. – Joel Nov 07 '17 at 18:34
8

Also, make sure the Console is actually visible in Xcode (i.e., make sure the right-hand side icon is highlighted in blue, as per the image below). After I upgraded Xcode, it hide the Console and showed me just the Variables view. This made it look like NSLog() was not working properly, whereas it was indeed working correct, I just couldn't see the output.

enter image description here

Stewart Macdonald
  • 2,062
  • 24
  • 27
7

I can't see NSLog output in real iOS 10 device neither. If you're using real devices, you can open Devices window from Xcode (Shift + Command + 2) and see device logs there, but it's hard to look at your app's logs because the console shows logs from system and all apps.

(I'm using Xcode 7, so it's may not Xcode's problem but iOS 10 problem)

kientux
  • 1,782
  • 1
  • 17
  • 32
7

For anyone who comes upon this in the future. The reason NSLog doesn't print to syslog in iOS 10 and iOS 11 is due to Apple changing to Unified Logging.

You can see the WWDC talk about it here: https://developer.apple.com/videos/play/wwdc2016/721/

Documentation here: https://developer.apple.com/documentation/os/logging

From 10 on you should be using os_log instead of NSLog.

How to find the logs on disk: https://www.blackbagtech.com/blog/2017/09/22/accessing-unified-logs-image/

To summarize, the logs are located in /var/db/diagnostics which can be found for a VM at /Users/USERNAME/Library/Developer/CoreSimulator/Devices/SIMULATOR-GUID/data/var/db/

Copy all items inside diagnostics and uuidtext into a single folder (don't include the folders diagnostics or uuidtext just what is inside).

Rename that folder foldername.xarchive.

Open it in Console.app or use the OSX util log: log show <path to archive> --info --predicate <options>

shane
  • 415
  • 5
  • 18
6

Hmmm... it seems like the property "OS_ACTIVITY_MODE": "disable" PREVENTS NSlog from showing up in the Xcode 9 log.

Unchecking this value in my scheme restored my logs.

David Hersey
  • 1,049
  • 11
  • 13
1

I'm using Xcode 8,so I also encountered the same problem . And I solved this problem by adding value = disable on the simulator, but on a real machine I don't add value.

NSNoob
  • 5,548
  • 6
  • 41
  • 54
  • 1
    i'm having some issues with Xcode 9. i inserted the argument: OS_ACTIVITY_MODE but it seems don't works... – Alessio Campanelli Sep 20 '17 at 09:59
  • 4
    This solution will hide all NSLog starting with Xcode 9. To keep NSLog, replace `disable` with `default`. – Cœur Sep 27 '17 at 19:21
  • In my opinion this is the correct answer. `OS_ACTIVITY_MODE` with `disable` or `default` is direct – Greg Mar 24 '18 at 22:20
1

NSLog messages no longer displayed when I upgraded to Xcode 9.1 + iOS 11.1. Initially the accepted answer gave me a way to work around this using the Console app and enabling the Simulator (see Lucas' answer).

In the Console app under Action I tried selecting Include Debug Messages and deselecting Include Info Messages (so the Console isn't swamped with system messages). NSLog messages appeared in the Console window in Xcode but not in the Console app.

I realised there had to be a more direct way to disable or enable (i.e. default) NSLogs thanks to Coeur's comment in response to this answer. In my opinion it is the best answer because setting OS_ACTIVITY_MODE to disable or default will make more sense for beginners.

Greg
  • 1,750
  • 2
  • 29
  • 56