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

IosConsoleIos Simulator

Ios Problem Overview


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 Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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

Solution 3 - Ios

There's an option in the Simulator to open the console

Debug > Open System Log

or use the

keyboard shortcut: ⌘/

Simulator menu screenshot

Solution 4 - Ios

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

Solution 5 - Ios

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

Solution 6 - Ios

[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 Messages)

enter image description here

Please note that if you want to see a log from WebView(UIWebView or WKWebView) you should use Safary -> Develop -> device

[Find crash log]

Solution 7 - Ios

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 + /)

Solution 8 - Ios

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

Solution 9 - Ios

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

Solution 10 - Ios

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.

Web Development Tools

Solution 11 - Ios

In Xcode: View->Debug Area->Activate Console

enter image description here

Solution 12 - Ios

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.

Solution 13 - Ios

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.

Solution 14 - Ios

Download the safari technology review. With the simulator running, select develop > simulator > localhost

Solution 15 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1335015View Question on Stackoverflow
Solution 1 - IosfbernardoView Answer on Stackoverflow
Solution 2 - IosBen JacksonView Answer on Stackoverflow
Solution 3 - IosMark BridgesView Answer on Stackoverflow
Solution 4 - IosviteinfiniteView Answer on Stackoverflow
Solution 5 - IosrussbishopView Answer on Stackoverflow
Solution 6 - IosyoAlex5View Answer on Stackoverflow
Solution 7 - IoscprcrackView Answer on Stackoverflow
Solution 8 - Iosdjibouti33View Answer on Stackoverflow
Solution 9 - IosGurubaranView Answer on Stackoverflow
Solution 10 - IosMauView Answer on Stackoverflow
Solution 11 - IosLoLoView Answer on Stackoverflow
Solution 12 - IosbompfView Answer on Stackoverflow
Solution 13 - IosJulesView Answer on Stackoverflow
Solution 14 - IosmacView Answer on Stackoverflow
Solution 15 - IosAnkurView Answer on Stackoverflow