本文翻译自: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

如何在React Native中记录日志?相关推荐

  1. 如何在React Native中写一个自定义模块

    前言 在 React Native 项目中可以看到 node_modules 文件夹,这是存放 node 模块的地方,Node.js 的包管理器 npm 是全球最大的开源库生态系统.提到npm,一般指 ...

  2. 如何在 React Native 中写一个自定义模块

    前言 在 React Native 项目中可以看到 node_modules 文件夹,这是存放 node 模块的地方,Node.js 的包管理器 npm 是全球最大的开源库生态系统.提到npm,一般指 ...

  3. 如何在React Native中使用Redux Saga监视网络更改

    by Pritish Vaidya 通过Pritish Vaidya 如何在React Native中使用Redux Saga监视网络更改 (How to monitor network change ...

  4. 如何在React Native中创建精美的动画加载器

    by Vikrant Negi 通过Vikrant Negi 如何在React Native中创建精美的动画加载器 (How to create a beautifully animated load ...

  5. 如何在React Native中构建项目并管理静态资源

    by Khoa Pham 通过Khoa Pham 如何在React Native中构建项目并管理静态资源 (How to structure your project and manage stati ...

  6. 如何在React Native中使用react-navigation 5处理导航

    React-navigation is the navigation library that comes to my mind when we talk about navigation in Re ...

  7. 如何在React Native中使用文本输入组件?

    You know, an app becomes more authentic and professional when there is the interaction between the a ...

  8. 如何在React Native中使用React JS Hooks?

    In my articles, I'm going to be using either expo or snack online IDE and android emulator. 在我的文章中,我 ...

  9. 理解 React Native 中的 AJAX 请求

    曾经,大多数 Web 应用程序通过用户操作刷新整个网页以与 Web 服务器通信. 后来,AJAX(异步 JavaScript 和 XML)概念通过提供一种在后台与 Web 服务器通信的方式使 Web ...

最新文章

  1. Android 12正式发布:安卓历史最大设计变化、更流畅了!
  2. HTK学习2:工具使用
  3. spring框架 AOP核心详解
  4. linux中特殊字符的含义,Linux中的特殊符号以及特殊语法
  5. SAP Fiori Launchpad里home按钮的实现原理分析
  6. 我的世界javamod怎么装_「装修细节」除了中央空调外的高颜值装空调大法
  7. go语音实战读后感——一
  8. 【LeetCode】152. Maximum Product Subarray
  9. 李少华 linux内核,腾讯云CMQ消息队列在Linux环境下的使用
  10. Fiddler 5.0 中文版
  11. 分享一种快速制作证件照的方法,只要你有自拍照就完全ok啦
  12. 无需U盘最简单的系统重装Win10
  13. 聚类算法之K均值算法C++实现
  14. 移动前端开发的一些简单分类!
  15. 多边形的定义为什么要强调封闭图形_11.3.1 多边形讲解.ppt
  16. 博士申请 | 阿尔伯塔大学招收人工智能方向全奖博士生、硕士生
  17. MSSQL_8 操作结果集
  18. 构建数据平台探索智能应用,做企业数字化升级的得力助手
  19. windows s2019安装crucible-4.8.2
  20. 为什么建议将成员属性设置为私有

热门文章

  1. [转]给软件开发人员的几点建议
  2. Android开发之大位图压缩水印处理
  3. struts的DevMode模式
  4. Android JNI入门第六篇——基本数据类型使用
  5. c++ opencv 通过网络连接工业相机_OpenCV项目实战之零件缺陷检测(上)
  6. 有关线程的相关知识(下)
  7. 【Android UI设计与开发】第11期:顶部标题栏(二)ActionBar实现Tab选项卡和下拉导航列表
  8. 【Android UI设计与开发】第07期:底部菜单栏(二)Fragment的详细介绍和使用方法
  9. 常用服务器返回码意义
  10. HBase学习指南之HBase原理和Shell使用