308

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.

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
user1335015
  • 3,081
  • 2
  • 14
  • 7

16 Answers16

312

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

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
fbernardo
  • 10,016
  • 3
  • 33
  • 46
  • 14
    Is this still accurate? I'm not seeing anything from `console.log` in these log using `tail` or `Console.app` – Jeff Mar 11 '14 at 20:07
  • 3
    I am not getting any results either on OSX 10.10. those logs are there but my simulator is version 8.1 and the logs all are versions 7.1* – skift Dec 04 '14 at 19:30
  • 75
    iOS Simulator > Menu Bar > Debug > Open System Log – pkamb Apr 16 '15 at 20:57
  • 4
    Thanks! Its ~/Library/Logs/CoreSimulator//system.log these days though. – calimarkus Apr 29 '15 at 19:02
  • 7
    The answer from BYossarian is the "correct" one. "Develop menu in desktop safari that lets you see the iOS simulator console: Develop -> iPhone Simulator -> site name" – snobojohan Sep 08 '15 at 22:16
  • 5
    In case you're unsure of what `` to use (I was), you can also simply do: `tail -f ~/Library/Logs/CoreSimulator/*/system.log` which would render all but keep on tailing only the one that gets updated (most likely the running one) – Roberto Andrade Dec 03 '15 at 14:44
  • If you use fastlane, I added support for this in the 'scan' action in the Fastlane toolset: https://github.com/fastlane/fastlane/releases/tag/2.9.0 – Lyndsey Ferguson Jan 17 '17 at 20:04
  • 2
    Sorry, this log is almost empty for me, it should be polluted with many system messages similar to logcat on Android. – Martin Braun Jun 06 '22 at 16:28
  • Only the other answer worked for me https://stackoverflow.com/a/14415709/1740008 – cyrf Aug 31 '22 at 16:19
263

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

Ben Jackson
  • 11,722
  • 6
  • 32
  • 42
  • 1
    Note that you need a device or the Simulator running iOS >= 6. You also may have to enable Web Inspector support on iOS (Settings App > Safari > Advanced). – Julian D. Apr 17 '13 at 21:18
  • 2
    Looks like is now just: Develop > Simulator > (your simulator name) – Matt Jensen Sep 28 '16 at 16:44
  • 3
    I had to first open the Simulator, and then restart Safari in order to get the option this answer describes. But then it worked like a charm. – Zeth Jul 12 '20 at 15:03
  • 3
    This is the only one that worked for me. Also you have first to enable that Develop menu going to: Preferences > Advanced > [Check] Show Develop menu in menu bar. – Maximiliano Guerra Oct 08 '20 at 18:05
120

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

Debug > Open System Log

or use the

keyboard shortcut: ⌘/

Simulator menu screenshot

Mark Bridges
  • 8,228
  • 4
  • 50
  • 65
94

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
viteinfinite
  • 941
  • 6
  • 5
45

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

russbishop
  • 16,587
  • 7
  • 61
  • 74
  • 1
    This is the correct answer now as of Xcode 9.3, iOS 11. The locations mentioned in other answers is no longer correct. – Michael McGuire Mar 31 '18 at 18:16
  • This worked for me on Xcode Version 10.1 (10B61), iOS 12.1 Simulator. Using it to view iOS app console output in Emacs. Other answers worked in the past, but no longer. – tboyce12 Apr 18 '19 at 21:38
  • For me, the thing that worked was the order (I had Safari open before the Simulator and so the menu entry did not appear in Safari)! – Shmarkus Oct 27 '19 at 21:49
  • Where did you find the documentation for the "predicate" flag? – Hjulle May 13 '20 at 19:03
  • New to macOS 11 and iOS 14 simulators: `log help predicates` will give you more information. The predicate format follows NSPredicate. – russbishop Jun 24 '20 at 02:32
  • This is the best answer by a long way, if you can't use `idevicesyslog` with a simulator. – rustyMagnet Jun 25 '20 at 10:04
  • `xcrun simctl spawn booted log stream --level=debug` works for me! The other answers such as system.log does *not* show logs of my app – ch271828n Sep 11 '20 at 23:58
  • I've started using Logger in Swift to log info messages. I don't see them in Console.app. What I do see is some system events for the simulator I'm running when I launch the app. How do I see these Logger info messages? Is there a document that explains how to do this? – Victor Engel Jul 20 '22 at 14:57
24

Apple logs

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

enter image description here

Please note that if you want to see a log from WebView(UIWebView or WKWebView) you should use Safari Web Inspector

Device
- Settings -> Safari -> Advanced -> <check in> Web Inspector
Mac
- Safari -> Settings -> Advanced -> <check in> Show Develop menu in menu bar
- Develop -> <device>

[Find crash log]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
  • press `cmd` `then` `space bar` Type "`Console`" press `enter`. Btw. that should be the correct answer today. –  Nov 07 '19 at 13:40
  • This is the only true solution to get all logs of your simulator compared to logcat on Android. – Martin Braun Jun 06 '22 at 16:41
21

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

cprcrack
  • 17,118
  • 7
  • 88
  • 91
12

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

Hiren Dhamecha
  • 658
  • 5
  • 15
djibouti33
  • 12,102
  • 9
  • 83
  • 116
7

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

Gurubaran
  • 718
  • 8
  • 13
3

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

enter image description here

LoLo
  • 374
  • 2
  • 7
2

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

Mau
  • 1,257
  • 2
  • 15
  • 21
0

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.

bompf
  • 1,374
  • 1
  • 18
  • 24
0

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.

Jules
  • 631
  • 6
  • 14
0

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

mac
  • 318
  • 4
  • 16
0

My current go-to solution:

find $(xcrun simctl get_app_container $deviceId $appId data) -name \*.log | xargs tail -f

where appId is the application identifier, and deviceId is the device identifier (usually booted).

The find command allows for some flexibility in logging libraries, which don't always log to system.log.

jamesh
  • 19,863
  • 14
  • 56
  • 96
-3

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.

Ankur
  • 177
  • 3
  • 15