7

Question: How can we log messages and save it on the device for a production React Native Expo app?

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.
  • Expo support Amplitude and Segment, but they are more for analytics.

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. We can create our own node.js server to accept incoming log dumps as well, so a hosted service is not necessary.

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?

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

1 Answers1

2

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. 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.

Waheed Akhter
  • 347
  • 2
  • 13
  • You could write a function that appends a date by checking if there is already a key value pair with that key, and then fire an appendData() function that you have written. However I believe that ASYNCSTORAGE.setItem() 's default behavior is not to append data. – JohnyClash Oct 29 '22 at 23:57