How to solve the Logging problem for Offline Mobile Apps
As anyone knows, logs are extremely useful for debugging end user issues and monitoring the health of the application. Logs generated in the Mobile App should be shipped to a server for future processing. Moreover, other considerations need to be made when we are dealing with an offline mobile app.
We were building a companion offline mobile app for one of our existing web applications. For any application, it is very important that there is one single strategy in place to handle all the logs, be it from the web side or the mobile app side. In our case, the log data from the existing web application was being sent to Logstash for processing and can be visualized using Kibana and Grafana. To leverage the existing logging strategy, we decided that the Mobile logs should also be sent to Logstash.
To achieve mobile logging, the following approach was used:
The user logs are stored in the device in the form of a database or a file. All the operations are performed in the device’s native layer. The stored logs are processed and split into chunks of predetermined size. The chunks of logs are sent to the server periodically. The chunks are deleted from the device once they are successfully transmitted to the server.
- Processing such log data from mobile should not impact other web application service requests. We hence implemented two new micro services to process the mobile logs.
- Mobile Logger Service
- Mobile Logger Worker
- Mobile Logger Service:
- API will be exposed to capture logs through Basic / Token Based Authentication process.
- Uploads the log data received to S3 bucket as a file.
- Enqueues Uploaded S3 file URL to SQS
- Mobile Logger Worker:
- Dequeues the S3 URL from SQS.
- Fetches the log file from the particular S3 location.
- Processes the log file and sends to Logstash.