在 Exponent 应用里写日志和浏览器里是一样的: 使用 console.log
, console.warn
还有 console.error
.
注意: 暂时在 remote debugging mode 外我们不支持 console.table
.
当你打开一个 XDE 或者 exp 服务的 app, 这个 app 会发送日志到 server, 然后你就可以方便的查看。这就意味着你不需要非得设备连接在你的电脑上才可以看到日志 -- 实际上,即使地球另外一端的某个家伙打开了应用,你也可以看到他们设备上你的应用日志。
Note: 没有看到日志? 确保你使用至少 Exponent sdkVersion 7.0.0, 安装了exponent
npm 包, 而且已经导入 (比如: 在你的 main JS 顶部有import * as Exponent from 'exponent'
)。
如果你用我们的命令行 exp
的话,你也可以用 exp logs
来查看日志 (确保已经启动你的服务, 在项目目录 exp start
)。
通常不是必须的,但是如果你需要查看设备上所有日志,甚至包括其他 app 还有系统本身的日志, 你可以用下面的一些方法。
⌘ + /
, 或者 点击 Debug -> Open System Log
-- 这两种方式都会打开一个日志窗口,显示你设备里的所有日志,包含你的 Exponent app 的日志。instruments -s devices
iPhone 6s (9.2) [5083E2F9-29B4-421C-BDB5-893952F2B780]
tail -f ~/Library/Logs/CoreSimulator/DEVICE_CODE/system.log
, 比如: tail -f ~/Library/Logs/CoreSimulator/5083E2F9-29B4-421C-BDB5-893952F2B780/system.log
brew install libimobiledevice
idevicepair pair
idevicesyslog
adb logcat