首页指南参考教程

查看日志

了解如何在使用 Expo CLI 时查看日志、Android Studio 和 Xcode 中的原生日志以及系统日志。


在 React Native 应用中记录信息的工作方式与在 Web 浏览器中类似。你可以使用 console.logconsole.warnconsole.error。然而,有时,你可能想要深入了解有关应用中发生的情况的更多有用信息。为此,你可以使用原生日志和系统日志。

¥Logging information in a React Native app works similarly to in a web browser. You can use console.log, console.warn and console.error. However, at times, you might want to dive deep to get more useful information about what's happening in your app. For that, you can use native logs and system logs.

控制台日志

¥Console logs

当你运行 npx expo start 并连接设备时,控制台日志将显示在终端进程中。这些日志通过 Web 套接字从运行时发送到 Expo CLI,这意味着结果的保真度低于将开发工具直接连接到引擎的结果。

¥When you run npx expo start and connect a device, console logs will show up in the terminal process. These logs are sent from the runtime to Expo CLI over web sockets, meaning the results are lower fidelity than connecting dev tools directly to the engine.

你可以通过使用 Hermes连接检查器 创建开发版本来查看高保真日志并使用 console.table 等高级日志记录功能。

¥You can view high fidelity logs and use advanced logging functions like console.table by creating a development build with Hermes, and connecting the inspector.

原生日志

¥Native logs

你可以通过本地编译原生应用在 Android Studio 和 Xcode 中查看原生运行时日志。欲了解更多信息,请参阅 原生调试

¥You can view native runtime logs in Android Studio and Xcode by compiling the native app locally. For more information, see native debugging.

系统日志

¥System logs

虽然通常没有必要,但如果你想查看设备上发生的所有情况的日志,例如,甚至来自其他应用和操作系统的日志,你可以使用以下命令:

¥While it's usually not necessary, if you want to see logs for everything happening on your device, for example, even the logs from other apps and the OS, you can use the following commands:

Terminal
# Show system logs for an Android device with adb logcat
npx react-native log-android
# Show system logs for an iOS device
npx react-native log-ios
Expo 中文网 - 粤ICP备13048890号