简体   繁体   English

在Production React Native Expo App中登录设备

[英]Logging to Device in Production React Native Expo App

Question: How can we log messages and save it on the device for a production React Native Expo app? 问题:我们如何记录消息并将其保存在生产的React Native Expo应用程序的设备上?

Requirements 要求

  • Store log files on the mobile device 将日志文件存储在移动设备上
  • (Ideally) Log rotation, compression and/or pruning (理想情况下)原木旋转,压缩和/或修剪
  • Log files can be sent to a remote server on-demand (ie. user clicked a button) 日志文件可以按需发送到远程服务器(即用户单击按钮)

Candidates that are not suitable 不适合的候选人

  • Expo supports Sentry , but it is meant for crash reports. 世博会支持Sentry ,但它用于崩溃报告。
  • Expo support Amplitude and Segment , but they are more for analytics. 世博会支持AmplitudeSegment ,但它们更多地用于分析。

Sentry, Amplitude & Segment are not suitable because we are looking more of an implementation that does logging and dumping the logs to a remote server on-demand. Sentry,Amplitude&Segment不适合,因为我们正在寻找更多的实现,它可以按需记录日志并将日志转储到远程服务器。 We can create our own node.js server to accept incoming log dumps as well, so a hosted service is not necessary. 我们可以创建自己的node.js服务器来接受传入的日志转储,因此不需要托管服务。

Our app currently uses redux-persist , wondering if theres a solution (3rd-party library included) for logging to a persisted redux store compatible with React Native Expo apps? 我们的应用程序当前使用redux-persist ,想知道是否有解决方案(包括第三方库)登录到与React Native Expo应用程序兼容的持久化redux存储吗?

if you want to do everything yourself without using third party library. 如果您想自己做所有事情而无需使用第三方库。 Here is how I would suggest you to do it. 我将建议您这样做。 make a function say logMessage(message) this function will write the message to asyncstorage with current date as the key. 使一个函数说logMessage(message)这个函数将以当前日期为键将消息写入异步存储。 if any message is already logged for that particular date, this will append the message. 如果在该特定日期已经记录了任何消息,则它将附加消息。 and you can call this function wherever you want to log. 并且您可以在想要登录的任何地方调用此函数。 to send the logs to remote server it is upto you whether you want to send the logs of the current date or multiple dates or all of the logs. 要将日志发送到远程服务器,由您决定是发送当前日期的日志还是发送多个日期或所有日志的日志。 you may also want to write function that clears all the logs. 您可能还想编写清除所有日志的功能。 So AsyncStorage of react-native can do the work for you. 因此react-native的AsyncStorage可以为您完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM