如何在React Native中记录日志?

本文翻译自:How to do logging in React Native?

如何为Web开发时在React Native中记录变量,例如使用console.log


#1楼

参考:https://stackoom.com/question/22MNo/如何在React-Native中记录日志


#2楼

console.log works. console.log有效。

By default on iOS, it logs to the debug pane inside Xcode. 默认情况下,在iOS上,它记录到Xcode内的调试窗格中。

From the IOS simulator press ( + D ) and press Remote JS Debugging . 在IOS模拟器中,按( + D ),然后按Remote JS Debugging This will open a resource, http://localhost:8081/debugger-ui on localhost. 这将在本地主机上打开资源http:// localhost:8081 / debugger-ui From there use Chrome Developer tools javascript console to view console.log 从那里使用Chrome Developer工具javascript控制台查看console.log


#3楼

I had the same issue: console messages were not appearing in XCode's debug area. 我遇到了同样的问题:控制台消息未出现在XCode的调试区域中。 In my app I did cmd-d to bring up the debug menu, and remembered I had set "Debug in Safari" on. 在我的应用程序中,我使用cmd-d调出了调试菜单,并记得我已将“在Safari中调试”设置为打开。

I turned this off, and some messages were printed to the output message, but not my console messages. 我关闭了此功能,并且一些消息被打印到输出消息中,但没有打印到控制台消息中。 However, one of the log messages said: 但是,其中一条日志消息说:

__DEV__ === false, development-level warning are OFF, performance optimizations are ON"

This was because I had previously bundled my project for testing on a real device with the command: 这是因为我以前使用以下命令将项目捆绑在一起,以便在实际设备上进行测试:

react-native bundle --minify

This bundled without "dev-mode" on. 这捆绑了没有“开发模式”。 To allow dev messages,include the --dev flag: 要允许开发人员消息,请包括--dev标志:

react-native bundle --dev

And console.log messages are back! 并且console.log消息又回来了! If you aren't bundling for a real device, don't forget to re-point jsCodeLocation in AppDelegate.m to localhost (I did!). 如果您不是要捆绑真实设备,请不要忘记将AppDelegate.m jsCodeLocation指向本地主机(我做到了!)。


#4楼

Visual Studio Code has a decent debug console that can show your console.log. Visual Studio Code有一个不错的调试控制台,可以显示您的console.log。

在此处输入图片说明

VS Code is, more often than not, React Native friendly. VS Code通常是React Native友好的。


#5楼

Use console.log , console.warn etc. 使用console.logconsole.warn等。

As of React Native 0.29 you can simply run the following to see logs in the console: 从React Native 0.29开始,您只需运行以下命令即可在控制台中查看日志:

$ react-native log-ios
$ react-native log-android

#6楼

Press [command + control + Z] in Xcode Simulator, choose Debug JS Remotely, then press [command + option + J] to open Chrome developer tools. 在Xcode Simulator中按[command + control + Z],选择“远程调试JS”,然后按[command + option + J]打开Chrome开发者工具。

Xcode Simulator Img Xcode模拟器图

refer: Debugging React Native Apps 参考: 调试React Native Apps

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值