iOS (iPhone, iPad, iPodTouch) view real-time console log terminal - ios

Is there a way to view the real-time console log to view NSLog and other debug messages in a real-time manner, such as adb logcat?

The solution documented by Apple in Technical Q&A QA1747 Debugging Deployed iOS Apps for Xcode 6 is:
Choose Window -> Devices from the Xcode menu.
Choose the device in the left column.
Click the up-triangle at the bottom left of the right hand panel to show the device console.

Two options:
libimobiledevice is installable via homebrew and works great. Its idevicesyslog tool works similarly to deviceconsole (below), and it supports wirelessly viewing your device's syslog (!)
I've written more about that on Tumblr tl;dr:
brew install libimobiledevice
idevice_id --list // list available device UDIDs
idevicesyslog -u <device udid>
with the device connected via USB or available on the local wireless network.
(Keeping for the historical record, from 2013:) deviceconsole from rpetrich is a much less wacked-out solution than ideviceconsole above. My fork of it builds and runs in Xcode 5 out of the box, and the Build action will install the binary to /usr/local/bin for ease of use.
As an additional helpful bit of info, I use it in the following style which makes it easy to find the device I want in my shell history and removes unnecessary > lines that deviceconsole prints out.
deviceconsole -d -u <device UDID> | uniq -u && echo "<device name>"

EDIT: Please use #cbowns solution - deviceconsole is compatible with iOS9 and much easier to use.
This is a open-source program that displays the iDevice's system log in Terminal (in a manner similar to tail -F). No jailbreak is required, and the output is fully grep'able so you can filter to see output from your program only. What's particularly good about this solution is you can view the log whether or not the app was launched in debug mode from XCode.
Here's how:
Grab the libimobiledevice binary for Mac OS X from my github account at
https://github.com/benvium/libimobiledevice-macosx/zipball/master
Follow the install instructions here:
https://github.com/benvium/libimobiledevice-macosx/blob/master/README.md
Connect your device, open up Terminal.app and type:
idevicesyslog
Up pops a real-time display of the device's system log.
With it being a console app, you can filter the log using unix commands, such as grep
For instance, see all log messages from a particular app:
idevicesyslog | grep myappname
Taken from my blog at http://pervasivecode.blogspot.co.uk/2012/06/view-log-output-of-any-app-on-iphone-or.html

Just open the Application Console.app on mac osX.
You can find it under Applications > Utilities > Console.
On the left side of the application all your connected devices are listed.

Try the freeware iOS Console. Just download, launch, connect your device -- et voila!

This might be what you're looking for: Xcode Organizer

device > terminal output is on iPhone configuration app
here: http://support.apple.com/kb/DL1465

You have three options:
Xcode Organizer
Jailbroken device with syslogd + openSSH
Use dup2 to redirect all STDERR and STDOUT to a file and then "tail -f" that file (this last one is more a simulator thing, since you are stuck with the same problem of tailing a file on the device).
So, to get the 2º one you just need to install syslogd and OpenSSH from Cydia, restart required after to get syslogd going; now just open a ssh session to your device (via terminal or putty on windows), and type "tail -f /var/log/syslog". And there you go, wireless real time system log.
If you would like to try the 3º just search for "dup2" online, it's a system call.

To view your iOS device's console in Safari on your Mac (Mac only apparently):
On your iOS device, go to Settings > Safari > Advanced and switch on Web Inspector
On your iOS device, load your web page in Safari
Connect your device directly to your Mac
On your Mac, if you've not already got Safari's Developer menu activated, go to Preferences > Advanced, and select "Show Develop menu in menu bar"
On your Mac, go to Develop > [your iOS device name] > [your web page]
Safari's Inspector will appear showing a console for your iOS device.

As an alternative, you can use an on-screen logging tool like ticker-log to view logs without having (convenient) access to the console.

Related

Xcode 11.3 could not attach to the pid: <Number> without internet

Error Prompt
Xcode 11.3 not able to run the simulator when the lab being "offline" I need to connect to the internet to make the Xcode run the simulator. I found this is hard, please note I try to the following possible solutions but no one solve the problem.
Remove driven data
Erase all content and setting from the simulator
Enable AuthDevTools
There are several answers about this issue.
1st way
You should run this command in your terminal ->
sudo DevToolsSecurity -enable
2nd way
Uncheck this box ->
Edit Scheme > Run > Debug executable
Resource for this answer
Developer Apple Thread
Bonus
What is the DevToolsSecurity -enable command?
This is the command we can use for enable Developer Mode
When you run Xcode for the first time on a fresh system, it asks if you’d like to enable Developer Mode. Developer Mode allows Xcode to execute common debugging tasks without constantly asking for your password.
Brian Gilham's Medium Article

Can I somehow read the iOS device logs before the phone is unlocked

After a hard reset (holding power+home) I would like to be able to see the iOS System logs after the phone boots. Using Xcode I can open the "Devices" tool, but unless I unlock the phone I cannot attach to the device to see the logs.
Is there a way to see the iPhone device logs while the phone is booting? Either in real-time or as a log file that I can examine afterwards.
I have also tried using the "View device logs" button in the Devices Tool, but all that I can see in there are crash logs.
Yes, it is possible, there are few options out there, one of my favorites is idevicesyslog, do the following:
Install brew on your mac:
http://coolestguidesontheplanet.com/installing-homebrew-os-x-yosemite-10-10-package-manager-unix-apps/
Using brew, install libimobiledevice
brew install libimobiledevice
Once done, connect idevice to mac and type in terminal
idevicesyslog
Note: if there is more than 1 device connected to the mac, you will need to specify the device udid you wish to work with. In order to get the device udid, run the following command:
idevice_id -l
Then run idevicesyslog, but this time specify the udid:
idevicesyslog -u <device udid>

Xcode 7.1 : Simulator can't be opened because the identity of developer cannot be confirmed

I've upgraded my Mac OS X to 10.11.1 El Capitan. When I try to run app on Xcode 7.1 I'm getting an pop message stating "Simulator" can't be opened because the identity of the developer cannot be confirmed. Refer screenshot.
Why this message? I'm not able to test any app on Xcode 7.1.
Gatekeeper requires that every application downloaded from the internet is verified. Since you downloaded "Simulator" with Safari it has to be checked and added to a list of accepted applications. Here is a quick way to do that:
Run Terminal.app
Enter the following command sudo xattr -d com.apple.quarantine /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
I found the answer here.
Apple believes is security that's the reason only apps which you have downloaded from App Store can be opened.
Well, to open any app which you have downloaded and install from anywhere you need to allow permission. To do so:
Open 'System Preferences'
Go to 'Security & Privacy' and tap on 'General' tab
Click on 'Lock' icon which you can find on bottom left screen and type your administrator password.
The last step is to choose 'Anywhere' under 'Allow apps downloaded from:' and then again click on 'Lock' icon.
That's it. Now you can run any apps.
Enjoy!
Simulator.app is distributed by Apple and should be codesigned appropriately.
The dialog you are seeing indicates that the version you have did not pass Gatekeeper's codesignature checks.
Possible causes:
You made local modifications to Xcode.app or Simulator.app to invalidate Apple's code signature.
Disk corruption or maybe an error in transport caused some resources in Simulator.app to not be valid such that the signature is no longer valid.
You downloaded an unofficial copy of Xcode.app (or just Simulator.app) which has been modified by a 3rd party. Google "XcodeGhost" for information on why that's a bad idea.
The Simulator.app you are trying to open is not actually Xcode's.
A bug in Gatekeeper or OS X might be triggering a false result.
Please also update your question with the output of the following steps (assuming you've setup xcode-select appropriately) for additional support:
codesign -vvv -d $(xcode-select -p)/Applications/Simulator.app
codesign -vvv $(xcode-select -p)/Applications/Simulator.app
This happened to me when I ran a build script that launched the simulator directly, before actually opening Xcode.
When you open Xcode for the first time it will go through a verification process that takes a long time. After that completes, the contents of the bundle will be verified as well and you can use the simulator without the warning.
If you still have the warning after verification your version of Xcode might be compromised.
It is possibly a bug that gatekeeper doesn't warn you that the parent bundle has not been verified.
In my case I had multiple instances of Simulator.app present (some downloaded directly from Apple's site, rather than installed from the store). When I issued open -b com.apple.iphonesimulator one of the downloaded simulators got opened, instead of the current one in /Applications/Xcode.app. I changed my command to open -a /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app and the issue is now resolved.

Corona SDK and lldb

Whether it possible to debug corona SDK application on iOS simulator?
I build a Corona SDK application for Xcode simulator and wrote next commands:
cd /Users/username/Library/Application\ Support/iPhone\ Simulator/7.0.3/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/app-name.app/
lldb
(lldb) attach --name "app-name" --waitfor
Then I run app in simulator and I get the next message from lldb:
error: attach failed: process did not stop (no such process or permission problem?)
Are you logged in to the Mac remotely (ssh or whatever)? You need to authorize debugging the first time you use the debugger. It's easy to verify if your machine is set up to allow debugging:
% /usr/sbin/DevToolsSecurity -status
Developer mode is currently enabled.
If it's not enabled, I think sudo /usr/sbin/DevToolsSecurity -enable may do the trick. If you're debugging locally, you should see a pop-up window asking you if you want to allow the debugging to happen. But when logged in remotely, you won't see that pop-up of course.

How can I get the console logs from the iOS Simulator?

I want to see what happens in the iOS Simulator if I'm not testing the app in Xcode.
For example, if I open a link in the Safari simulator, see what happens in the console,
or if I install a web-app, see the links that I'm pressing in console.
How can I do this?
I want to see it in Xcode or Terminal, but it's not a problem if I need to use another bit of software.
iOS Simulator > Menu Bar > Debug > Open System Log
Old ways:
iOS Simulator prints its logs directly to stdout, so you can see the logs mixed up with system logs.
Open the Terminal and type: tail -f /var/log/system.log
Then run the simulator.
EDIT:
This stopped working on Mavericks/Xcode 5. Now you can access the simulator logs in its own folder: ~/Library/Logs/iOS Simulator/<sim-version>/system.log
You can either use the Console.app to see this, or just do a tail (iOS 7.0.3 64 bits for example):
tail -f ~/Library/Logs/iOS\ Simulator/7.0.3-64/system.log
EDIT 2:
They are now located in ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log
tail -f ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log
You can view the console for the iOS Simulator via desktop Safari. It's similar to the way you use desktop Safari to view the console for physical iOS devices.
Whenever the simulator is running and there's a webpage open, there'll be an option under the Develop menu in desktop safari that lets you see the iOS simulator console:
Develop -> iPhone Simulator -> site name
There's an option in the Simulator to open the console
Debug > Open System Log
or use the
keyboard shortcut: ⌘/
iOS 8 and iOS 9
Under iOS 8 and iOS 9 this location is now:
~/Library/Logs/CoreSimulator/<DEVICE_CODE>
So, the following will work:
tail -f ~/Library/Logs/CoreSimulator/<DEVICE_CODE>/system.log
The DEVICE_CODE value can be found via the following terminal command:
instruments -s devices
You should not rely on instruments -s. The officially supported tool for working with Simulators from the command line is xcrun simctl.
The log directory for a device can be found with xcrun simctl getenv booted SIMULATOR_LOG_ROOT. This will always be correct even if the location changes.
Now that things are moving to os_log it is easier to open Console.app on the host Mac. Booted simulators should show up as a log source on the left, just like physical devices. You can also run log commands in the booted simulator:
# os_log equivalent of tail -f
xcrun simctl spawn booted log stream --level=debug
# filter log output
xcrun simctl spawn booted log stream --predicate 'processImagePath endswith "myapp"'
xcrun simctl spawn booted log stream --predicate 'eventMessage contains "error" and messageType == info'
# a log dump that Console.app can open
xcrun simctl spawn booted log collect
# open location where log collect will write the dump
cd `xcrun simctl getenv booted SIMULATOR_SHARED_RESOURCES_DIRECTORY`
If you want to use Safari Developer tools (including the JS console) with a webpage in the Simulator: Start one of the simulators, open Safari, then go to Safari on your mac and you should see Simulator in the menu.
You can open a URL in the Simulator by dragging it from the Safari address bar and dropping on the Simulator window. You can also use xcrun simctl openurl booted <url>.
[iOS Logger]
You can use the Console application(select your device in Devices) on your Mac to see a log message that were sent using NSLog, os_log, Logger (you will not see logs from print function).
Also please check (Action -> Include <Info/Debug> Messages)
Please note that if you want to see a log from WebView(UIWebView or WKWebView) you should use Safary -> Develop -> device
[Find crash log]
If you are using Swift, remember that println will only print to the debug log (which appears in xCode's debug area). If you want to print to system.log, you have to use NSLog as in the old days.
Then you can view the simulator log via its menu, Debug > Open System Log... (cmd + /)
tailing /var/log/system.log didn't work for me. I found my logs by using Console.app. They were in
~/Library/Logs/iOS Simulator/{version}/system.log
XCode > 6.0 AND iOS > 8.0
The below script works if you have XCode version > 8.0
I use the below small Script to tail the simulator logs onto the system console.
#!/bin/sh
sim_dir=`xcrun instruments -s | grep "iPhone 6 (8.2 Simulator)" | awk {'print $NF'} | tr -d '[]'`
tail -f ~/Library/Logs/CoreSimulator/$sim_dir/system.log
You can pass in the simulator type used in the Grep as an argument. As mentioned in the above posts, there are simctl and instruments command to view the type of simulators available for use depending on the Xcode version.
To View the list of available devices/simulators.
xcrun instruments -s
OR
xcrun simctl list
Now you can pass in the Device code OR Simulator type as an argument to the script and replace the "iPhone 6 (8.2 Simulator)" inside grep to be $1
You can see the Simulator console window, including Safari Web Inspector and all the Web Development Tools by using the Safari Technology Preview app.
Open your page in Safari on the Simulator and then go to Safari Technology Preview > Develop > Simulator.
In Xcode:
View->Debug Area->Activate Console
I can open the log directly via the iOS simulator: Debug -> Open System Log... Not sure when this was introduced, so it might not be available for earlier versions.
No NSLog or print content will write to system.log, which can be open by Select Simulator -> Debug -> Open System log on Xcode 11.
I figure out a way, write logs into a file and open the xx.log with Terminal.app.Then the logs will present in Terminal.app lively.
I use CocoaLumberjack achieve this.
STEP 1:
Add DDFileLogger DDOSLogger and print logs path. config() should be called when App lunch.
static func config() {
#if DEBUG
DDLog.add(DDOSLogger.sharedInstance) // Uses os_log
let fileLogger: DDFileLogger = DDFileLogger() // File Logger
fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hours
fileLogger.logFileManager.maximumNumberOfLogFiles = 7
DDLog.add(fileLogger)
DDLogInfo("DEBUG LOG PATH: " + (fileLogger.currentLogFileInfo?.filePath ?? ""))
#endif
}
STEP 2:
Replace print or NSLog with DDLogXXX.
STEP 3:
$ tail -f {path of log}
Here, message will present in Terminal.app lively.
One thing more. If there is no any message log out, make sure Environment Variables -> OS_ACTIVITY_MODE ISNOT disable.
Download the safari technology review. With the simulator running, select develop > simulator > localhost
The easiest way to see the console logs is by adding consolelogs as a param:
ionic cordova run ios -l --consolelogs
And you'll able to see the console logs in your terminal.

Resources