Javascript 如何在离子模拟器中观看console.logs?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28611375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to watch console.logs in ionic emulator?
提问by kramer65
I'm building an app using the Ionic framework, which I've done in the browser until now. Because I now want to use the cordovaOauth pluginI need to use the emulator. The problem is that I can't see any console.log() in the emulator as I do in the browser, which makes it hard to debug.
我正在使用Ionic 框架构建一个应用程序,到目前为止我一直在浏览器中完成。因为我现在想使用cordovaOauth插件,所以我需要使用模拟器。问题是我在模拟器中看不到任何 console.log() ,就像在浏览器中一样,这使得调试变得困难。
Does anybody know how in Ionic/Cordova I can make use of console logging in the emulator? All tips are welcome!
有人知道如何在 Ionic/Cordova 中使用模拟器中的控制台日志记录吗?欢迎所有提示!
回答by Carlos Barcelona
Just enable the console logs in the emulator. Here my example:
只需在模拟器中启用控制台日志即可。这是我的例子:
> ionic emulate ios --livereload
Setup Live Reload
Running dev server: http://localhost:8100
Adding in default Ionic hooks
Running live reload server: http://localhost:35729
Watching : [ 'www/**/*', '!www/lib/**/*' ]
Ionic server commands, enter:
restart or r to restart the client app from the root
goto or g and a url to have the app navigate to the given url
consolelogs or c to enable/disable console log output
serverlogs or s to enable/disable server log output
quit or q to shutdown the server and exit
Type consolelogsin the command line and hit enter.
键入consolelogs的命令行并回车。
consolelogs
Console log output: enabled
Loading: /?restart=382451
ionic $ 0 498458 log Hi there! This is from console.log
回答by Yaron U.
run ionic emulate ios -l -c
跑 ionic emulate ios -l -c
This will open the emulator with livereload feature, and you'll see all the console logs in the terminal.
To turn the console logs off (or on) just write consolelogsor just cin the terminal while the ionic server is running
这将打开具有 livereload 功能的模拟器,您将在终端中看到所有控制台日志。要关闭(或打开)控制台登录,consolelogs只需c在 ionic 服务器运行时写入或仅在终端中
Another very convenient way to debug your app when using iOS emulator/device is using the Safari developer tools
使用 iOS 模拟器/设备时调试应用程序的另一种非常方便的方法是使用 Safari 开发人员工具
When the app runs - enter Safari and choose "Develop > iOS Simulator > your page"
当应用程序运行时 - 进入 Safari 并选择“Develop > iOS Simulator > your page”
If you work with a real device you'll see the device's name instead of "iOS Simulator"
如果您使用真实设备,您将看到设备名称而不是“iOS 模拟器”
If you don't see the "Develop" menu in safari - enter Safari's preferences and enable it from the "advanced" tab
如果您在 safari 中没有看到“开发”菜单 - 输入 Safari 的首选项并从“高级”选项卡启用它
回答by S.Thiongane
If you wan't to watch console logs in emulator / simulator use
ionic emulate -l -c <PLATFORM>If you wan't to watch console logs when testing in device you can launch this command :
ionic run -l -c <PLATFORM>
如果您不想在模拟器/模拟器中观看控制台日志,请使用
ionic emulate -l -c <PLATFORM>如果在设备中测试时不想查看控制台日志,可以启动以下命令:
ionic run -l -c <PLATFORM>
-c = --consolelogs: Print app console logs to Ionic CLI (livereload req.)
-l = --livereload: Live reload app dev files from the device
-c = --consolelogs: 将应用程序控制台日志打印到 Ionic CLI (livereload req.)
-l = --livereload:从设备实时重新加载应用程序开发文件
May help someone !
可以帮助某人!
回答by Ruchir Shukla
If you are testing your web app with a device running Android 4.4 or higher, you can remotely debug your web pages in WebView with Chrome Developer Tools. Just open chrome://inspect on your desktop with the phone in USB Debugging mode connected.
如果您正在使用运行 Android 4.4 或更高版本的设备测试您的网络应用程序,您可以使用 Chrome 开发人员工具在 WebView 中远程调试您的网页。只需在连接 USB 调试模式的手机的情况下,在桌面上打开 chrome://inspect。
回答by user15163
There are a few ways to debug your ionic app.
有几种方法可以调试您的 ionic 应用程序。
- In the browser you can catch the errors in the console.
- If you are emulating your app on a simulator or a mobile device you can install the cordova plugin that displays js errors in the xcode console. So you can emulate your device and catch errors on xcode.
- 在浏览器中,您可以在控制台中捕获错误。
- 如果您在模拟器或移动设备上模拟您的应用程序,您可以安装在 xcode 控制台中显示 js 错误的 cordova 插件。因此,您可以模拟您的设备并在 xcode 上捕获错误。
Here is how you add the plugin:
添加插件的方法如下:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
Hope this helps! It came in very handy for me while I was debugging GeoFire errors and testing the cordova camera and geolocation api.
希望这可以帮助!当我调试 GeoFire 错误并测试cordova 相机和地理定位api 时,它对我来说非常方便。
回答by slider
On Ionic 3, you can do this by
在 Ionic 3 上,您可以通过
ionic cordova run android --emulator -l -c
Replace androidwith iosdepending on your requirements. More information here: https://ionicframework.com/docs/cli/cordova/run/
根据您的要求替换android为ios。更多信息在这里:https: //ionicframework.com/docs/cli/cordova/run/

