iOS 10 doesn't print NSLogs - ios

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

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)
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.

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)

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.

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.

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)

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>

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.

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.

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.

Related

refreshPreferences HangTracerEnabled / HangTracerDuration messages in iOS 11 + Xcode 9

When update to iOS 11, after run app in iPhone, I receive this message in Xcode console:
SibDiet[924:111682] refreshPreferences: HangTracerEnabled: 0
SibDiet[924:111682] refreshPreferences: HangTracerDuration: 500
SibDiet[924:111682] refreshPreferences: ActivationLoggingEnabled: 0 ActivationLoggingTaskedOffByDA:0
And now I get this message in every simulator and app.
How can I solve this problem?
You can hide this message with click left mouse button on your target, and next Edit Scheme.
After that in section Environment Variables create variable with name OS_ACTIVITY_MODE and value disable as on the picture below.
At this point, there are no data to suggest that you need to respond to this spewing of internal debugger status. BTW, these messages also appear when developing on physical devices, not just simulators.
The prior answer of disabling the Xcode Environment Variable OS_ACTIVITY_MODE will stop all such internal system messages with the unfortunate side effect of turning off console logging from NSLog() calls in ObjC. I have not checked, but it may also disable Swift print() logging.
The Xcode team should really discriminate between disabling system logging and user logging!
It seems the (refresh preferences...) problem appears on multiple platforms.
I managed to fix it on High Sierra(10.13.1) XCode 9.1 and with iOS 11.0.3 by defining OS_ACTIVITY_MODE as disable by going in XCode via
Product > Scheme > Edit Scheme > Arguments > Environment Variables
add OS_ACTIVITY_MODE disable
Note: NSLog may not work after doing this.
Similar issue is reported in the question:
How to fix refreshPreferences Message in Xcode 9 [duplicate]

How to debug iOS 9 extensions

Is there a way I can debug my networkextension (NEPacketTunnelProvider)? .
I use NSLog but not use for extension (only for container app). I found system log in window -> devices, but only have crash logs.
so I can only debug by breakpoint(debug -> attach) . but it's really really annoying me for a long time. Can I view log (NSLog) in somewhere?
You can..
First Start Your container App.
Switch to Your Extension App in xCode.
Go To Debug and choose attach to process..
Put the breakpoints to debug than

nw_host_stats_add_src recv too small, received 24, expected 28

nw_host_stats_add_src recv too small, received 24, expected 28
So I'm getting this appear in the console and I'm not sure whether it is an issue that I should be bothered about or not. I noticed it after attaching my app to Firebase and writing to the database with anonymous sign in. Just wondering whether I need to do anything about this and if so what those actions would be.
Thanks!
This is a bug with logs in Xcode8 + iOS10.
We can get round it in this way:
When on simulator, add the Name OS_ACTIVITY_MODE and the Value
Variables disable and check it (Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment).
When on device, only add OS_ACTIVITY_MODE and check it(don't add the Value). You'll see the NSLog in the Xcode8 Console.
Cause: iOS 10 & Xcode 8. Also can be replicated by an odd inputField bug:
Issue belongs to an InputField whom width is smaller than the inputs
chars : 96px vs (4 * 28px)
This leads to a 100% CPU and it is fixed
when width is set to 128px
Link to the above fix and reasoning
Or just silence everything:
Press ⌘<
Edit simulator scheme by adding or setting the OS_ACTIVITY_MODE under Environment Variables in the Run Arguments to a value of disable.
Do the same for the device but remove the value for OS_ACTIVITY_MODE , leaving it empty. The logs will display for the device as they should.
I found this answer in a video on Reddit located here: https://www.reddit.com/r/ios/comments/5p0fvy/xcode_nw_host_stats_add_src_recv_too_small/
This warning comes from XCode and can be disabled by adding an Environmental variable to the Scheme's Run section. The Environmental name is OS_ACTIVITY_MODE and the value is "disable".
This appears to suppress all of the "nw_" warning messages. Note that this just suppresses the warnings. I'm not sure if the warnings are significant or not or whether this indicates that there are "real" underlying problems that should be fixed.
How to edit a Scheme's Run Environmental Variables section in XCode
Adding the OS_ACTIVITY_MODE value of "disable"
I was getting this exact same error message on Xcode-8.2 iOS-10.2, but I was not using Firebase, so I'm not sure if that makes a difference. Setting OS_ACTIVITY_MODE to disable did not solve the problem, however, I realized it was coming from the All Exceptions Breakpoint I had set. I changed it to from All to Objective-C (removing C) and it no longer stops on that line anymore. You can do this by right-clicking on breakpoint in the breakpoints tab on the left, then selecting edit, then making the change.

IOS App crashes, but there is no crash log available

I am starting my App from XCode and with a specific behaviour it just disconnects and the app disappears from my IPAD screens.
So I guess the app crashes.
Now my question. Where Do I get this crashlog ? I already looked into
Window -> Devices -> choose my Ipad -> "View Device Logs" . But I cant see any actual crash log. I have some from earlier times, but my actual doesn't show up.
How do I get a crashlog ?
check if you have enabled Share with app developers option in settings. Privacy -> Analytics -> Share with App Developers.Xcode was not showing crash logs, enabling this helped me
You need to look at the device console under windows, devices in Xcode.
Its possibly saying something about code signing, bundle id's or missing libraries.
Try to delete the crash logs from "earlier times".
You have maximum amount of saved crash logs, and if you passed it - you won't see the new crash logs

NSLog not showing in handleWatchKitExtensionRequest, but breakpoints works [duplicate]

I'm just getting started with Apple Watch. I found instructions from "Five Minute Watchkit", on getting the iOS app and the watch kit app both running in the simulator and both processes attached to the LLDB debugger.
What I do is launch and quit the iOS app to install a current version in the sim. Then I switch to the watchKit scheme and launch that, which displays my watch app UI on the watch simulator.
I then launch the corresponding iOS app in the simulator, then user "attach to process" in the Xcode menu to attach the debugger to the running iOS app.
This works. I can set breakpoints in either the watch kit InterfaceController or in my iOS app and the debugger breaks there when it should.
However, I'm not seeing NSLog() statements in the debug console from my iOS app. (I do see log statements from the WatchKit extension code.) If I set a breakpoint in my iOS app, it does stop at that breakpoint when it should. I assume the lack of console output from NSLog has SOMETHING to do with attaching to a running process on the sim rather than launching it from Xcode, but I don't know what that something is.
(BTW, attaching an action to a breakpoint that invokes NSLog from the breakpoint also doesn't display, but the "log message" debugger command DOES display.
Does anybody have any insights?)
EDIT:
The code in the iOS app doesn't seem to matter. In my case, it was a dirt simple IBAction that was attached to a button in the iOS app storyboard:
- (IBAction)buttonAction:(UIButton *)sender;
{
NSLog(#"Button clicked on iPhone");
}
I can set a breakpoint on that NSLog statement. The debugger stops at that line, but I don't see the log statement in the debug console.
I can reproduce that with a simple test app, sans WatchKit. The app consists of a NSTimer that prints "Timer fired" every second. (This code is 100% correct ;). Nothing shows in the log after I have manually attached to the process.
As far as I know NSLog outputs to stderr, I guess attaching the debugger does not redirect stderr to the Xcode terminal.
If you are okay with using the console app or the terminal to look at your logs you can do that. iOS8 stores simulator logs in ~/Library/Logs/CoreSimulator/<Device-UUID>. In this directory you will find a system.log, which contains all your NSLog output.
You can look at it in terminal (cat, grep, tail), or open it in the Console.app.
Apple confirms that (at least for GDB) in Technical Note TN2239: iOS Debugging Magic.
Console Output
Many programs, and indeed many system frameworks, print debugging
messages to stderr. The destination for this output is ultimately
controlled by the program: it can redirect stderr to whatever
destination it chooses. However, in most cases a program does not
redirect stderr, so the output goes to the default destination
inherited by the program from its launch environment. This is
typically one of the following:
If you launch a GUI application as it would be launched by a normal
user, the system redirects any messages printed on stderr to the
system log. You can view these messages using the techniques described
earlier.
If you run a program from within Xcode, you can see its
stderr output in Xcode's debugger Console window (choose the Console
menu item from the Run menu to see this window).
Attaching to a
running program (using Xcode's Attach to Process menu, or the attach
command in GDB) does not automatically connect the program's stderr to
your GDB window. You can do this from within GDB using the trick
described in the "Seeing stdout and stderr After Attaching" section of
Technical Note TN2030, 'GDB for MacsBug Veterans'.
The mentioned TN2030 is no longer available on their server (mirror). It showed how you can redirect stdout and stderr to the Xcode console. However, since shell tty isn't a valid command for LLDB it won't help much. But maybe there is a different way to access the tty Xcodes console uses, so I attach the important part of that TN.
Seeing stdout and stderr After Attaching
If you attach GDB to a process (as opposed to starting the process
from within GDB), you won't be able to see anything that the process
prints to stdout or stderr. Programs launched by the Finder typically
have stdout and stderr connected to "/dev/console", so the information
they print goes to the console. You can view this by launching the
Console application (in the Utilities folder), however, it's
inconvenient to have to look in a separate window. Another alternative
is to connect the process's stdout or stderr to the terminal device
for GDB's Terminal window. Listing 9 shows how to do this.
Listing 9. Connecting stdout and stderr to GDB's terminal device.
(gdb) attach 795
[... output omitted ...]
(gdb) call (void) DebugPrintMenuList()
No output )-:
Close the stdout and stderr file descriptors.
(gdb) call (void) close(1)
(gdb) call (void) close(2)
Determine the name of the terminal device for GDB itself.
(gdb) shell tty
/dev/ttyp1
Reopen stdout and stderr, but connected to GDB's terminal.
The function results should be 1 and 2; if not, something
is horribly wrong.
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$1 = 1
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$2 = 2
Try the DebugPrintMenuList again.
(gdb) call (void) DebugPrintMenuList()
Yay output!
Index MenuRef ID Title
----- ---------- ---- -----
<regular menus>
00001 0x767725D3 -21629 Ed
00002 0x76772627 1128 <Apple>
00003 0x767726CF 1129 File
00004 0x76772567 1130 Edit
[... remaining output omitted ...]
To add onto Filipp Keks answer, here's a visual representation of a much much simpler way to do it than the accepted answer.
From Filipp Keks's answer:
Plug in the device and open Xcode
Choose Window -> Devices from the menu bar
Under the DEVICES section in the left column, choose the device
To see the device console, click the up-triangle at the bottom left of the right hand panel
Click the down arrow on the bottom right to save the console as a file"
This screenshot was taken in Xcode 7.3.1 of the Devices window.
With Xcode Version 7.2 and iOS 9.2 etc, I found the following works:
Kill both the phone app and watch apps
Select the Watch Extension Target and hit Cmd+R (build and run)
Select the Phone target and hit Ctrl+Cmd+R (Run without building)
In my case, I have both apps up in their simulators and get NSLog output for both. I don't need to attach separately. Hope this helps.
https://developer.apple.com/library/ios/qa/qa1747/_index.html
Plug in the device and open Xcode
Choose Window -> Devices from the menu bar
Under the DEVICES section in the left column, choose the device
To see the device console, click the up-triangle at the bottom left of the right hand panel
Click the down arrow on the bottom right to save the console as a file
When your Provisioning profile is set to AdHoc or Distribution then Xcode doesnot show log, you need set development to view log
This might not solve showing up NSLog messages, but it might be helpful when debugging app started in background.
You can use the breakpoint feature that allows you to log messages.
The idea is to:
Create a breakpoint with "Automatically continue after evaluating actions" checked
add "Log message" action (you can also use expressions and print out values, for example: "Log message #variable#")
Attach debugger using anticipated process name (XCode will wait for the process to start)
Trigger app start.
Credits and details:
https://fluffy.es/how-to-debug-app-which-got-launched-push-notification/
In my case a set Automatically to see NSLog, before don't show at all
I came to this question, via this one (Xcode console empty after attaching to process) which is now closed.
My issue is that the debug console in Xcode is showing nothing (just an empty white box).
The solution for me is a tiny toggle at the bottom which changes between "variable view" and the actual debug console.

Resources