如何从iOS模拟器获得控制台日志?

时间:2022-07-31 20:44:57

I want to see what happens in the iOS Simulator if I'm not testing the app in Xcode.

我想看看如果我不在Xcode中测试这个应用会在iOS模拟器中发生什么。

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.

例如,如果我在Safari模拟器中打开一个链接,看看在控制台上会发生什么,或者如果我安装了一个web应用程序,就会看到我正在控制的链接。

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.

我想在Xcode或者Terminal上看到它,但是如果我需要使用其他的软件,这不是问题。

9 个解决方案

#1


240  

iOS Simulator > Menu Bar > Debug > Open System Log

iOS模拟器>菜单栏>调试>打开系统日志


Old ways:

老方法:

iOS Simulator prints its logs directly to stdout, so you can see the logs mixed up with system logs.

iOS模拟器直接将其日志打印到stdout,因此您可以看到日志与系统日志混合在一起。

Open the Terminal and type: tail -f /var/log/system.log

打开终端并输入: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

这停止了Mavericks/Xcode 5。现在您可以在它自己的文件夹中访问模拟器日志:~/Library/ logs /iOS模拟器/ /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):

您可以使用控制台。应用程序看到这个,或者做一个尾巴(iOS 7.0.3 64位):

tail -f ~/Library/Logs/iOS\ Simulator/7.0.3-64/system.log

tail - f ~ /图书馆/日志/ iOS \模拟器/ 7.0.3-64 / system.log

EDIT 2:

编辑2:

They are now located in ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log

它们现在位于~/Library/Logs/ Logs/CoreSimulator/ /system.log中

tail -f ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log

tail - f ~ /图书馆/日志/ CoreSimulator / < simulator-hash > / system.log

#2


193  

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.

您可以通过桌面Safari查看iOS模拟器的控制台。它类似于使用桌面Safari查看物理iOS设备的控制台。

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:

只要模拟器在运行,有网页打开,桌面safari中的“开发”菜单就会有一个选项,让你看到iOS模拟器控制台:

Develop -> iPhone Simulator -> site name

开发-> iPhone模拟器->网站名称

#3


93  

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

在模拟器中有一个选项可以打开控制台

Debug > Open System Log

or use the

keyboard shortcut: ⌘/

或使用键盘快捷键:⌘/

如何从iOS模拟器获得控制台日志?

#4


88  

iOS 8 and iOS 9

Under iOS 8 and iOS 9 this location is now:

在ios8和ios9下,这个位置现在是:

~/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 console command:

DEVICE_CODE值可以通过以下控制台命令找到:

instruments -s devices

#5


14  

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.

如果您正在使用Swift,请记住,println将只打印到调试日志(出现在xCode的debug区域)。如果你想打印到系统。log,你必须像以前一样使用NSLog。

Then you can view the simulator log via its menu, Debug > Open System Log... (cmd + /)

然后你可以通过它的菜单查看模拟器日志,调试>打开系统日志…(cmd + /)

#6


11  

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

尾矿/var/log/system.log对我没用。我通过使用Console.app找到了我的日志。它们在~/Library/Logs/iOS模拟器/{version}/system.log中

#7


7  

XCode > 6.0 AND iOS > 8.0 The below script works if you have XCode version > 8.0

XCode > 6.0和ios> 8.0如果你有XCode版本> 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.

您可以将Grep中使用的模拟器类型作为参数传入。正如上面提到的,simctl和instruments命令可以根据Xcode版本查看可用的模拟器类型。查看可用设备/模拟器的列表。

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

现在,您可以将设备代码或模拟器类型传递给脚本,并将grep中的“iPhone 6(8.2模拟器)”替换为$1。

#8


7  

You should not rely on instruments -s. The officially supported tool for working with Simulators from the command line is xcrun simctl.

你不应该依赖乐器s。使用命令行中的模拟器的官方支持工具是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.

可以在xcrun simctl getenv引导的SIMULATOR_LOG_ROOT中找到一个设备的日志目录。即使位置改变了,这也是正确的。

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,打开控制台更容易了。启动模拟器应该显示为左边的日志源,就像物理设备一样。您还可以在启动模拟器中运行日志命令:

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

如果你想在模拟器中使用Safari开发者工具(包括JS控制台):启动一个模拟器,打开Safari,然后在mac上运行Safari,你应该在菜单中看到模拟器。

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

通过从Safari地址栏拖拽到模拟器窗口,可以在模拟器中打开URL。您还可以使用xcrun simctl openurl引导的

#9


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.

我可以通过iOS模拟器直接打开日志:Debug ->打开系统日志…不知道这是什么时候引入的,所以可能不能用于早期版本。

#1


240  

iOS Simulator > Menu Bar > Debug > Open System Log

iOS模拟器>菜单栏>调试>打开系统日志


Old ways:

老方法:

iOS Simulator prints its logs directly to stdout, so you can see the logs mixed up with system logs.

iOS模拟器直接将其日志打印到stdout,因此您可以看到日志与系统日志混合在一起。

Open the Terminal and type: tail -f /var/log/system.log

打开终端并输入: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

这停止了Mavericks/Xcode 5。现在您可以在它自己的文件夹中访问模拟器日志:~/Library/ logs /iOS模拟器/ /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):

您可以使用控制台。应用程序看到这个,或者做一个尾巴(iOS 7.0.3 64位):

tail -f ~/Library/Logs/iOS\ Simulator/7.0.3-64/system.log

tail - f ~ /图书馆/日志/ iOS \模拟器/ 7.0.3-64 / system.log

EDIT 2:

编辑2:

They are now located in ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log

它们现在位于~/Library/Logs/ Logs/CoreSimulator/ /system.log中

tail -f ~/Library/Logs/CoreSimulator/<simulator-hash>/system.log

tail - f ~ /图书馆/日志/ CoreSimulator / < simulator-hash > / system.log

#2


193  

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.

您可以通过桌面Safari查看iOS模拟器的控制台。它类似于使用桌面Safari查看物理iOS设备的控制台。

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:

只要模拟器在运行,有网页打开,桌面safari中的“开发”菜单就会有一个选项,让你看到iOS模拟器控制台:

Develop -> iPhone Simulator -> site name

开发-> iPhone模拟器->网站名称

#3


93  

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

在模拟器中有一个选项可以打开控制台

Debug > Open System Log

or use the

keyboard shortcut: ⌘/

或使用键盘快捷键:⌘/

如何从iOS模拟器获得控制台日志?

#4


88  

iOS 8 and iOS 9

Under iOS 8 and iOS 9 this location is now:

在ios8和ios9下,这个位置现在是:

~/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 console command:

DEVICE_CODE值可以通过以下控制台命令找到:

instruments -s devices

#5


14  

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.

如果您正在使用Swift,请记住,println将只打印到调试日志(出现在xCode的debug区域)。如果你想打印到系统。log,你必须像以前一样使用NSLog。

Then you can view the simulator log via its menu, Debug > Open System Log... (cmd + /)

然后你可以通过它的菜单查看模拟器日志,调试>打开系统日志…(cmd + /)

#6


11  

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

尾矿/var/log/system.log对我没用。我通过使用Console.app找到了我的日志。它们在~/Library/Logs/iOS模拟器/{version}/system.log中

#7


7  

XCode > 6.0 AND iOS > 8.0 The below script works if you have XCode version > 8.0

XCode > 6.0和ios> 8.0如果你有XCode版本> 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.

您可以将Grep中使用的模拟器类型作为参数传入。正如上面提到的,simctl和instruments命令可以根据Xcode版本查看可用的模拟器类型。查看可用设备/模拟器的列表。

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

现在,您可以将设备代码或模拟器类型传递给脚本,并将grep中的“iPhone 6(8.2模拟器)”替换为$1。

#8


7  

You should not rely on instruments -s. The officially supported tool for working with Simulators from the command line is xcrun simctl.

你不应该依赖乐器s。使用命令行中的模拟器的官方支持工具是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.

可以在xcrun simctl getenv引导的SIMULATOR_LOG_ROOT中找到一个设备的日志目录。即使位置改变了,这也是正确的。

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,打开控制台更容易了。启动模拟器应该显示为左边的日志源,就像物理设备一样。您还可以在启动模拟器中运行日志命令:

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

如果你想在模拟器中使用Safari开发者工具(包括JS控制台):启动一个模拟器,打开Safari,然后在mac上运行Safari,你应该在菜单中看到模拟器。

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

通过从Safari地址栏拖拽到模拟器窗口,可以在模拟器中打开URL。您还可以使用xcrun simctl openurl引导的

#9


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.

我可以通过iOS模拟器直接打开日志:Debug ->打开系统日志…不知道这是什么时候引入的,所以可能不能用于早期版本。